def setup_truss1(self): nodeA = Node(1, [0., 0.], ndof=2) nodeB = Node(2, [1., 0.], ndof=2) nodeC = Node(3, [1., 1.], ndof=2) nodeD = Node(4, [0., 1.], ndof=2) nodes = [nodeA, nodeB, nodeC, nodeD] E = 1.e11 area = .02 element1 = Rod(1, [nodeA, nodeD], E=E, area=area) element2 = Rod(2, [nodeD, nodeC], E=E, area=area) element3 = Rod(3, [nodeC, nodeB], E=E, area=area) element4 = Rod(4, [nodeD, nodeB], E=E, area=area) elements = [element1, element2, element3, element4] displacements = { 1: [0., 0.], 2: [0., 0.], 3: [None, None], 4: [None, None] } loads = {1: [None, None], 2: [None, None], 3: [10., 0.], 4: [0., 0.]} return nodes, elements, displacements, loads
def test_element_labels(): node = Node('http://example.com#1', {RDF_TYPE: [NTWK_SERVICE]}) assert len(node.labels) == 0, 'Should be 0' labels = ['hello world'] node = Node('http://example.com#1', { RDF_TYPE: [NTWK_SERVICE], RDFS_LABEL: labels }) assert node.labels == labels, 'Should be {}'.format(labels)
def test_node_equality(self): x = 4.0 y = 5.0 geometry = Geometry(2.0, 3.8, x, y) node1 = Node('id', 'key', 'text', 'rect', None, geometry, None, None) node2 = Node('id', 'key', 'text', 'rect', None, geometry, None, None) assert ( node1.geometry.x == node2.geometry.x and node1.geometry.y == node2.geometry.y ) assert node1 == node2
def test_add_edge(self): assert not self.graph.edges geometry = Geometry(2, 3, 4, 23) n1 = Node('n1', 'key', 'text', 'rect', None, geometry, None, None) geometry.translate(2) n2 = Node('n2', 'key', 'text', 'rect', None, geometry, None, None) self.graph.nodes['n1'] = n1 self.graph.nodes['n2'] = n2 self.graph.add_edge(self.edge_id, source=n1.id, target=n2.id) assert self.graph.edges assert isinstance(self.graph.edges[self.edge_id], Edge) assert self.graph.edges[self.edge_id].source == n1 assert self.graph.edges[self.edge_id].target == n2
def test_node(): url = 'http://example.com#1' types = [NTWK_SERVICE] node = Node(url, {RDF_TYPE: types}) assert node.id == url, 'Should be {}'.format(url) assert node.data == { RDF_TYPE: types }, 'Should be {}'.format({RDF_TYPE: types}) assert not node.source assert not node.target
def test_node_location_relation(): geometry = Geometry(3.8, 2.0, 4.0, 13.21) node = Node('id', 'key', 'text', 'rect', None, geometry, None, None) # test comparison between non-Node with pytest.raises(TypeError): node.location_relation(Point) # test when width == 0, y == 0 node.geometry.width = 0.0 node.geometry.height = 0.0 geometry.translate(2) node2 = Node('id', 'key', 'text', 'rect', None, geometry, None, None) x, y = node.location_relation(node2) assert x == node.geometry.x assert y == node.geometry.y
def test_node_coordinates(): geometry = Geometry(3.8, 2.0, 4.0, 13.21) node = Node('id', 'key', 'text', 'rect', None, geometry, None, None) assert node.coordinates[0] == node.geometry.x assert node.coordinates[1] == node.geometry.y
def test_node_lt(self): geometry = Geometry(2.0, 3.8, 1.3, 2.2) node1 = Node('id', 'key', 'text', 'rect', None, geometry, None, None) geometry.scale(4) node2 = Node('id', 'key', 'text', 'rect', None, geometry, None, None) assert node1 < node2
def setup_rod2(self): node1 = Node(1, [1., 0.], ndof=2) node2 = Node(2, [0., 1.], ndof=2) rod = Rod(1, [node1, node2], E=1.*10e11, area=0.02) return rod, [node1, node2]
def test_element_types(): types = [NTWK_SERVICE] node = Node('http://example.com#1', {RDF_TYPE: types}) assert node.types == types, 'Should be {}'.format(types)
def test_element_has_type(): node = Node('http://example.com#1', {RDF_TYPE: [NTWK_SERVICE]}) assert node.has_type(NTWK_SERVICE), 'Should be True' assert not node.has_type(NTWK_IP), 'Should be False'
def test_element_is_edge(): node = Node('http://example.com#1', {RDF_TYPE: [NTWK_SERVICE]}) assert not node.is_edge, 'Should be False' edge = Edge('http://example.com#1', NTWK_HOSTS, 'http://example.com#2') assert edge.is_edge, 'Should be True'