File: graph.cpp

package info (click to toggle)
antimony 0.9.3-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,480 kB
  • sloc: cpp: 42,596; ansic: 28,661; python: 1,093; yacc: 128; lex: 114; sh: 90; makefile: 10
file content (72 lines) | stat: -rw-r--r-- 1,519 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <Python.h>

#include <catch/catch.hpp>

#include "graph/graph.h"
#include "graph/node.h"
#include "graph/datum.h"

TEST_CASE("Name validity")
{
    REQUIRE(Graph::isNameValid("hithar"));
    REQUIRE(Graph::isNameValid("__hello"));
    REQUIRE(Graph::isNameValid("hi1"));

    REQUIRE(!Graph::isNameValid("1hi"));
    REQUIRE(!Graph::isNameValid(""));
    REQUIRE(!Graph::isNameValid("for"));
}

TEST_CASE("Graph name generation")
{
    auto g = new Graph();
    new Node("n", g);
    REQUIRE(g->nextName("n") == "n0");

    new Node("n0", g);
    REQUIRE(g->nextName("n") == "n1");

    new Node("n2", g);
    REQUIRE(g->nextName("n") == "n1");

    delete g;
}

TEST_CASE("Wildcard node names")
{
    auto g = new Graph();
    new Node("n", g);
    new Node("n1", g);
    REQUIRE(g->nextName("n") == "n0");

    auto n0 = new Node("n*", g);
    REQUIRE(n0->getName() == "n0");

    auto n2 = new Node("n*", g);
    REQUIRE(n2->getName() == "n2");

    delete g;
}

TEST_CASE("Duplicate name validity")
{
    auto g = new Graph();
    auto a = new Node("n", g);
    auto b = new Node("n", g);

    REQUIRE(!g->isNameUnique("n"));
    REQUIRE(g->isNameUnique("n", a));
    REQUIRE(!g->isNameUnique("n", b));
}

TEST_CASE("Getting multiple UIDs")
{
    auto g = new Graph();
    auto a = new Node("a", g);
    auto b = new Node("b", g);
    auto c = new Node("c", g);

    REQUIRE(g->getUIDs(3) == std::list<uint64_t>({3,4,5}));
    g->uninstall(b);
    REQUIRE(g->getUIDs(3) == std::list<uint64_t>({1,3,4}));
}