File: node.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 (58 lines) | stat: -rw-r--r-- 1,527 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
#include <Python.h>

#include <catch/catch.hpp>

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

TEST_CASE("Cross-node datum deletion")
{
    auto g = new Graph();
    auto a = new Node("a", g);
    auto ax = new Datum("x", "3.0", &PyFloat_Type, a);
    auto b = new Node("b", g);
    auto bx = new Datum("x", "a.x", &PyFloat_Type, b);

    a->uninstall(ax);
    REQUIRE(bx->isValid() == false);
    CAPTURE(bx->getError());
    REQUIRE(bx->getError().find("Name 'x' is not defined")
            != std::string::npos);

    g->uninstall(a);
    REQUIRE(bx->isValid() == false);
    CAPTURE(bx->getError());
    REQUIRE(bx->getError().find("Name 'a' is not defined")
            != std::string::npos);
}

TEST_CASE("Cross-node node deletion")
{
    auto g = new Graph();
    auto a = new Node("a", g);
    auto ax = new Datum("x", "3.0", &PyFloat_Type, a);
    auto b = new Node("b", g);
    auto bx = new Datum("x", "a.x", &PyFloat_Type, b);

    g->uninstall(a);
    REQUIRE(bx->isValid() == false);
    CAPTURE(bx->getError());
    REQUIRE(bx->getError().find("Name 'a' is not defined")
            != std::string::npos);
}

TEST_CASE("Cross-node name creation")
{
    auto g = new Graph();
    auto a = new Node("a", g);
    auto ax = new Datum("x", "b.x", &PyFloat_Type, a);
    CAPTURE(ax->getError());
    REQUIRE(ax->isValid() == false);

    auto b = new Node("b", g);
    auto bx = new Datum("x", "1.0", &PyFloat_Type, b);

    CAPTURE(ax->getError());
    REQUIRE(ax->isValid() == true);
}