def test_spiral_layout_hole(self): g = retworkx.generators.path_graph(5) g.remove_nodes_from([1]) res = retworkx.spiral_layout(g) expected = { 0: (-0.6415327868391166, -0.6855508729419231), 2: (-0.03307913182988828, -0.463447951079834), 3: (0.34927952438480797, 0.1489988240217569), 4: (0.32533239428419697, 1.0), } self.assertLayoutEquiv(expected, res)
def test_spiral_layout_equidistant(self): res = retworkx.spiral_layout(self.graph, equidistant=True) expected = { 0: (-0.13161882865656718, -0.7449342807652114), 1: (0.7160560542246066, -0.6335352483233974), 2: (0.6864868274284994, -0.34165899654603915), 3: (0.5679822628330004, -0.07281296883784087), 4: (0.375237081214659, 0.14941210155952697), 5: (0.12730720268992277, 0.30830226777240866), 6: (-0.15470865936858091, 0.3939608192236113), 7: (-0.4495426197217269, 0.4027809258196645), 8: (-0.7371993206438128, 0.33662707199446507), 9: (-1.0, 0.2018583081028111), } self.assertLayoutEquiv(expected, res)
def test_spiral_layout_resolution(self): res = retworkx.spiral_layout(self.graph, resolution=0.6) expected = { 0: (0.14170895375949058, 0.22421978768273812), 1: (0.2657196183870804, 0.30906004798138936), 2: (0.2506009612140119, 0.5043065412934762), 3: (0.039294315670400995, 0.6631957258449066), 4: (-0.3014789232909145, 0.6301862160709318), 5: (-0.602046830323471, 0.3302396035952633), 6: (-0.66674476042188, -0.17472522299849289), 7: (-0.3739394496041176, -0.6924895145748617), 8: (0.2468861146093996, -0.9732085843739783), 9: (1.0, -0.8207846005213728), } self.assertLayoutEquiv(expected, res)
def test_spiral_layout_center(self): res = retworkx.spiral_layout(self.graph, center=(1, 1)) expected = { 0: (1.3083011152777302, 0.6315812967715462), 1: (1.4448595378922136, 0.681429012234928), 2: (1.5306742824266686, 0.8188836315878713), 3: (1.5252997033017661, 1.0098782575185785), 4: (1.4071349204896917, 1.2046082065491848), 5: (1.178741251211811, 1.3468009691240852), 6: (0.8679584050988116, 1.3844997574641718), 7: (0.5245110970688955, 1.2805728884166347), 8: (0.2125196872324111, 1.0211642834109833), 9: (1.1102230246251565e-16, 0.6205816969220161), } self.assertLayoutEquiv(expected, res)
def test_spiral_layout_scale(self): res = retworkx.spiral_layout(self.graph, scale=2) expected = { 0: (0.6166022305554606, -0.7368374064569075), 1: (0.8897190757844272, -0.6371419755301438), 2: (1.0613485648533374, -0.36223273682425755), 3: (1.0505994066035322, 0.01975651503715709), 4: (0.8142698409793833, 0.4092164130983693), 5: (0.35748250242362195, 0.6936019382481704), 6: (-0.2640831898023768, 0.7689995149283434), 7: (-0.950977805862209, 0.5611457768332697), 8: (-1.5749606255351778, 0.042328566821966625), 9: (-1.9999999999999998, -0.7588366061559678), } self.assertLayoutEquiv(expected, res)
def test_spiral_layout(self): res = retworkx.spiral_layout(self.graph) expected = { 0: (0.3083011152777303, -0.36841870322845377), 1: (0.4448595378922136, -0.3185709877650719), 2: (0.5306742824266687, -0.18111636841212878), 3: (0.5252997033017661, 0.009878257518578544), 4: (0.40713492048969163, 0.20460820654918466), 5: (0.17874125121181098, 0.3468009691240852), 6: (-0.1320415949011884, 0.3844997574641717), 7: (-0.4754889029311045, 0.28057288841663486), 8: (-0.7874803127675889, 0.021164283410983312), 9: (-0.9999999999999999, -0.3794183030779839), } self.assertLayoutEquiv(expected, res)
def test_spiral_layout_one_node(self): res = retworkx.spiral_layout(retworkx.generators.path_graph(1)) self.assertEqual({0: (0.0, 0.0)}, res)
def test_spiral_layout_empty(self): res = retworkx.spiral_layout(retworkx.PyGraph()) self.assertEqual({}, res)