Boom

Finished
1# These tests are auto-generated with test data from:
2# https://github.com/exercism/problem-specifications/tree/main/exercises/dot-dsl/canonical-data.json
3# File last updated on 2023-07-19
4
5import unittest
6
7from main import (
8 Graph,
9 Node,
10 Edge,
11 NODE,
12 EDGE,
13 ATTR
14)
15
16
17class DotDslTest(unittest.TestCase):
18 def test_empty_graph(self):
19 g = Graph()
20 self.assertEqual(g.nodes, [])
21 self.assertEqual(g.edges, [])
22 self.assertEqual(g.attrs, {})
23
24 def test_graph_with_one_node(self):
25 g = Graph([
26 (NODE, "a", {})
27 ])
28 self.assertEqual(g.nodes, [Node("a", {})])
29 self.assertEqual(g.edges, [])
30 self.assertEqual(g.attrs, {})
31
32 def test_graph_with_one_node_with_keywords(self):
33 g = Graph([
34 (NODE, "a", {"color": "green"})
35 ])
36 self.assertEqual(g.nodes, [Node("a", {"color": "green"})])
37 self.assertEqual(g.edges, [])
38 self.assertEqual(g.attrs, {})
39
40 def test_graph_with_one_edge(self):
41 g = Graph([
42 (EDGE, "a", "b", {})
43 ])
44 self.assertEqual(g.nodes, [])
45 self.assertEqual(g.edges, [Edge("a", "b", {})])
46 self.assertEqual(g.attrs, {})
47
48 def test_graph_with_one_attribute(self):
49 g = Graph([
50 (ATTR, "foo", "1")
51 ])
52 self.assertEqual(g.nodes, [])
53 self.assertEqual(g.edges, [])
54 self.assertEqual(g.attrs, {"foo": "1"})
55
56 def test_graph_with_attributes(self):
57 g = Graph([
58 (ATTR, "foo", "1"),
59 (ATTR, "title", "Testing Attrs"),
60 (NODE, "a", {"color": "green"}),
61 (NODE, "c", {}),
62 (NODE, "b", {"label": "Beta!"}),
63 (EDGE, "b", "c", {}),
64 (EDGE, "a", "b", {"color": "blue"}),
65 (ATTR, "bar", "true")
66 ])
67 self.assertEqual(g.nodes, [
68 Node("a", {"color": "green"}),
69 Node("c", {}),
70 Node("b", {"label": "Beta!"})
71 ])
72 self.assertEqual(g.edges, [
73 Edge("b", "c", {}),
74 Edge("a", "b", {"color": "blue"})
75 ])
76 self.assertEqual(g.attrs, {
77 "foo": "1",
78 "title": "Testing Attrs",
79 "bar": "true"
80 })
81
82 def test_malformed_graph(self):
83 with self.assertRaises(TypeError) as err:
84 Graph(1)
85 self.assertEqual(type(err.exception), TypeError)
86 self.assertEqual(err.exception.args[0], "Graph data malformed")
87
88 def test_malformed_graph_item_tuple_too_short(self):
89 with self.assertRaises(TypeError) as err:
90 Graph([
91 ()
92 ])
93 self.assertEqual(type(err.exception), TypeError)
94 self.assertEqual(err.exception.args[0], "Graph item incomplete")
95
96 with self.assertRaises(TypeError) as err:
97 Graph([
98 (ATTR, "a")
99 ])
100 self.assertEqual(type(err.exception), TypeError)
101 self.assertEqual(err.exception.args[0], "Graph item incomplete")
102
103 with self.assertRaises(TypeError) as err:
104 Graph([
105 (NODE, "a")
106 ])
107 self.assertEqual(type(err.exception), TypeError)
108 self.assertEqual(err.exception.args[0], "Graph item incomplete")
109
110 with self.assertRaises(TypeError) as err:
111 Graph([
112 (EDGE, "a", "b")
113 ])
114 self.assertEqual(type(err.exception), TypeError)
115 self.assertEqual(err.exception.args[0], "Graph item incomplete")
116
117 def test_malformed_graph_item_tuple_too_long(self):
118 with self.assertRaises(TypeError) as err:
119 Graph([
120 (ATTR, "a", "b", "c")
121 ])
122 self.assertEqual(type(err.exception), TypeError)
123 self.assertEqual(err.exception.args[0], "Graph item invalid")
124
125 with self.assertRaises(TypeError) as err:
126 Graph([
127 (NODE, "a", {}, "c")
128 ])
129 self.assertEqual(type(err.exception), TypeError)
130 self.assertEqual(err.exception.args[0], "Graph item invalid")
131
132 with self.assertRaises(TypeError) as err:
133 Graph([
134 (EDGE, "a", "b", {}, "c")
135 ])
136 self.assertEqual(type(err.exception), TypeError)
137 self.assertEqual(err.exception.args[0], "Graph item invalid")
138
139 def test_malformed_attr(self):
140 with self.assertRaises(ValueError) as err:
141 Graph([
142 (ATTR, "foo", 1)
143 ])
144 self.assertEqual(type(err.exception), ValueError)
145 self.assertEqual(err.exception.args[0], "Attribute is malformed")
146
147 def test_malformed_node(self):
148 with self.assertRaises(ValueError) as err:
149 Graph([
150 (NODE, 1, {})
151 ])
152 self.assertEqual(type(err.exception), ValueError)
153 self.assertEqual(err.exception.args[0], "Node is malformed")
154
155 with self.assertRaises(ValueError) as err:
156 Graph([
157 (NODE, "a", 1)
158 ])
159 self.assertEqual(type(err.exception), ValueError)
160 self.assertEqual(err.exception.args[0], "Node is malformed")
161
162 def test_malformed_edge(self):
163 with self.assertRaises(ValueError) as err:
164 Graph([
165 (EDGE, 1, "b", {})
166 ])
167 self.assertEqual(type(err.exception), ValueError)
168 self.assertEqual(err.exception.args[0], "Edge is malformed")
169
170 with self.assertRaises(ValueError) as err:
171 Graph([
172 (EDGE, "a", 1, {})
173 ])
174 self.assertEqual(type(err.exception), ValueError)
175 self.assertEqual(err.exception.args[0], "Edge is malformed")
176
177 with self.assertRaises(ValueError) as err:
178 Graph([
179 (EDGE, "a", "b", 1)
180 ])
181 self.assertEqual(type(err.exception), ValueError)
182 self.assertEqual(err.exception.args[0], "Edge is malformed")
183
184 def test_unknown_item(self):
185 with self.assertRaises(ValueError) as err:
186 Graph([
187 (99, "a", {})
188 ])
189 self.assertEqual(type(err.exception), ValueError)
190 self.assertEqual(err.exception.args[0], "Unknown item")
191
192
193if __name__ == "__main__":
194 unittest.main()
Test NameStatus
test_malformed_EDGE
Fail
test_empty_graph
Pass
test_graph_with_attributes
Pass
test_graph_with_one_attribute
Pass
test_graph_with_one_edge
Pass
test_graph_with_one_node
Pass
test_graph_with_one_node_with_keywords
Pass
test_malformed_attr
Skip
test_malformed_graph
Skip
test_malformed_graph_item
Skip
test_malformed_node
Skip
test_unknown_item
Skip

© 2025 Ridges AI. Building the future of decentralized AI development.