Skip to content

Commit

Permalink
Tidied up some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evildmp committed May 7, 2022
1 parent 20844ef commit 1e8e2e7
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 129 deletions.
148 changes: 70 additions & 78 deletions tests/test_brachiograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,96 +5,88 @@
from brachiograph import BrachioGraph
import linedraw

bg = BrachioGraph(virtual=True)

# ----------------- set-up tests -----------------

bg2 = BrachioGraph(
virtual=True,
servo_1_angle_pws_bidi={
-135: {"cw": 2374, "acw": 2386},
-120: {"cw": 2204, "acw": 2214},
-105: {"cw": 2042, "acw": 2054},
-90: {"cw": 1898, "acw": 1900},
-75: {"cw": 1730, "acw": 1750},
-60: {"cw": 1604, "acw": 1612},
-45: {"cw": 1466, "acw": 1476},
-30: {"cw": 1330, "acw": 1340},
-15: {"cw": 1188, "acw": 1200},
0: {"cw": 1048, "acw": 1060},
15: {"cw": 904, "acw": 910},
30: {"cw": 750, "acw": 766},
},
servo_2_angle_pws_bidi={
15: {"cw": 783, "acw": 761},
30: {"cw": 917, "acw": 901},
45: {"cw": 1053, "acw": 1035},
60: {"cw": 1183, "acw": 1167},
75: {"cw": 1303, "acw": 1287},
90: {"cw": 1427, "acw": 1417},
105: {"cw": 1557, "acw": 1537},
120: {"cw": 1697, "acw": 1681},
135: {"cw": 1843, "acw": 1827},
150: {"cw": 2003, "acw": 1987},
},
pw_up=1400, # pulse-widths for pen up/down
pw_down=1650,
)


def test_defaults_of_default_bg():
assert (bg.angle_1, bg.angle_2) == (-90, 90)


def test_defaults_of_bg_with_bidi_pws():
assert bg2.get_pulse_widths() == (
approx(1894 + bg2.hysteresis_correction_1, abs=1e-0),
approx(1422 + bg2.hysteresis_correction_2, abs=1e-0),
)
assert (bg2.angle_1, bg2.angle_2) == (-90, 90)


# ----------------- drawing methods -----------------


def test_plot_from_file():
bg.plot_file("test-patterns/accuracy.json")


# ----------------- test pattern methods -----------------


def test_test_pattern():
bg.test_pattern()


def test_vertical_lines():
bg.vertical_lines()
class TestBrachioGraph:

bg = BrachioGraph(virtual=True)

def test_defaults_of_default_bg(self):
assert (self.bg.angle_1, self.bg.angle_2) == (-90, 90)


class TestBiDiBrachioGraph:

bg = BrachioGraph(
virtual=True,
servo_1_angle_pws_bidi={
-135: {"cw": 2374, "acw": 2386},
-120: {"cw": 2204, "acw": 2214},
-105: {"cw": 2042, "acw": 2054},
-90: {"cw": 1898, "acw": 1900},
-75: {"cw": 1730, "acw": 1750},
-60: {"cw": 1604, "acw": 1612},
-45: {"cw": 1466, "acw": 1476},
-30: {"cw": 1330, "acw": 1340},
-15: {"cw": 1188, "acw": 1200},
0: {"cw": 1048, "acw": 1060},
15: {"cw": 904, "acw": 910},
30: {"cw": 750, "acw": 766},
},
servo_2_angle_pws_bidi={
15: {"cw": 783, "acw": 761},
30: {"cw": 917, "acw": 901},
45: {"cw": 1053, "acw": 1035},
60: {"cw": 1183, "acw": 1167},
75: {"cw": 1303, "acw": 1287},
90: {"cw": 1427, "acw": 1417},
105: {"cw": 1557, "acw": 1537},
120: {"cw": 1697, "acw": 1681},
135: {"cw": 1843, "acw": 1827},
150: {"cw": 2003, "acw": 1987},
},
pw_up=1400, # pulse-widths for pen up/down
pw_down=1650,
)

def test_defaults_of_bg_with_bidi_pws(self):
assert self.bg.get_pulse_widths() == (
approx(1894 + self.bg.hysteresis_correction_1, abs=1e-0),
approx(1422 + self.bg.hysteresis_correction_2, abs=1e-0),
)
assert (self.bg.angle_1, self.bg.angle_2) == (-90, 90)

def test_horizontal_lines():
bg.horizontal_lines()
# ----------------- drawing methods -----------------

def test_plot_from_file(self):
self.bg.plot_file("test-patterns/accuracy.json")

def test_box():
bg.box()
# ----------------- test pattern methods -----------------

def test_test_pattern(self):
self.bg.test_pattern()

# ----------------- pen-moving methods -----------------
def test_vertical_lines(self):
self.bg.vertical_lines()

def test_horizontal_lines(self):
self.bg.horizontal_lines()

def test_centre():
bg.park()
def test_box(self):
self.bg.box()

# ----------------- pen-moving methods -----------------

# ----------------- reporting methods -----------------
def test_centre(self):
self.bg.park()

# ----------------- reporting methods -----------------

def test_report():
bg.report()
def test_report(self):
self.bg.report()


def test_maths_errors():
plotter = BrachioGraph(inner_arm=8.2, outer_arm=8.85, virtual=True)
with pytest.raises(Exception):
plotter.xy_to_angles(-10.2, 13.85)
class TestErrors:
def test_maths_errors(self):
plotter = BrachioGraph(inner_arm=8.2, outer_arm=8.85, virtual=True)
with pytest.raises(Exception):
plotter.xy_to_angles(-10.2, 13.85)
116 changes: 65 additions & 51 deletions tests/test_plotter.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,81 @@
from plotter import Plotter
from pytest import approx

bg = Plotter(virtual=True)

bg2 = Plotter(
virtual=True,
servo_1_angle_pws_bidi={
-135: {"cw": 2374, "acw": 2386},
-120: {"cw": 2204, "acw": 2214},
-105: {"cw": 2042, "acw": 2054},
-90: {"cw": 1898, "acw": 1900},
-75: {"cw": 1730, "acw": 1750},
-60: {"cw": 1604, "acw": 1612},
-45: {"cw": 1466, "acw": 1476},
-30: {"cw": 1330, "acw": 1340},
-15: {"cw": 1188, "acw": 1200},
0: {"cw": 1048, "acw": 1060},
15: {"cw": 904, "acw": 910},
30: {"cw": 750, "acw": 766},
},
servo_2_angle_pws_bidi={
15: {"cw": 783, "acw": 761},
30: {"cw": 917, "acw": 901},
45: {"cw": 1053, "acw": 1035},
60: {"cw": 1183, "acw": 1167},
75: {"cw": 1303, "acw": 1287},
90: {"cw": 1427, "acw": 1417},
105: {"cw": 1557, "acw": 1537},
120: {"cw": 1697, "acw": 1681},
135: {"cw": 1843, "acw": 1827},
150: {"cw": 2003, "acw": 1987},
},
pw_up=1400, # pulse-widths for pen up/down
pw_down=1650,
)
class TestBasicPlotter:

plotter = Plotter()

def test_defaults_of_default_bg():
assert bg.angles_to_pw_1 == bg.naive_angles_to_pulse_widths_1
assert bg.angles_to_pw_2 == bg.naive_angles_to_pulse_widths_2
assert bg.get_pulse_widths() == (1500, 1500)
def test_virtual(self):
assert self.plotter.virtual == True

def test_status_report(self):
self.plotter.status()

def test_defaults_of_bg_with_bidi_pws():
assert bg2.angles_to_pw_1 != bg2.naive_angles_to_pulse_widths_1
def test_defaults_of_default_plotter(self):
assert (
self.plotter.angles_to_pw_1 == self.plotter.naive_angles_to_pulse_widths_1
)
assert (
self.plotter.angles_to_pw_2 == self.plotter.naive_angles_to_pulse_widths_2
)
assert self.plotter.get_pulse_widths() == (1500, 1500)

assert bg2.angles_to_pw_1(-90) == approx(1894, abs=1e-0)
assert bg2.angles_to_pw_2(90) == approx(1422, abs=1e-0)
def test_can_land_at_0_degrees(self):
self.plotter.set_angles(0, 0)
assert (self.plotter.angle_1, self.plotter.angle_2) == (0, 0)

assert bg2.hysteresis_correction_1 == approx(5.416666)
assert bg2.hysteresis_correction_2 == approx(-8.3)
def test_xy(self):
self.plotter.xy(0, 6)

assert bg2.get_pulse_widths() == (
approx(1054 + bg2.hysteresis_correction_1, abs=1e-0),
approx(617 + bg2.hysteresis_correction_2, abs=1e-0),

class TestBiDiPlotter:

plotter = Plotter(
virtual=True,
servo_1_angle_pws_bidi={
-135: {"cw": 2374, "acw": 2386},
-120: {"cw": 2204, "acw": 2214},
-105: {"cw": 2042, "acw": 2054},
-90: {"cw": 1898, "acw": 1900},
-75: {"cw": 1730, "acw": 1750},
-60: {"cw": 1604, "acw": 1612},
-45: {"cw": 1466, "acw": 1476},
-30: {"cw": 1330, "acw": 1340},
-15: {"cw": 1188, "acw": 1200},
0: {"cw": 1048, "acw": 1060},
15: {"cw": 904, "acw": 910},
30: {"cw": 750, "acw": 766},
},
servo_2_angle_pws_bidi={
15: {"cw": 783, "acw": 761},
30: {"cw": 917, "acw": 901},
45: {"cw": 1053, "acw": 1035},
60: {"cw": 1183, "acw": 1167},
75: {"cw": 1303, "acw": 1287},
90: {"cw": 1427, "acw": 1417},
105: {"cw": 1557, "acw": 1537},
120: {"cw": 1697, "acw": 1681},
135: {"cw": 1843, "acw": 1827},
150: {"cw": 2003, "acw": 1987},
},
pw_up=1400, # pulse-widths for pen up/down
pw_down=1650,
)
assert (bg2.angle_1, bg2.angle_2) == (0, 0)

def test_defaults_of_bg_with_bidi_pws(self):
assert (
self.plotter.angles_to_pw_1 != self.plotter.naive_angles_to_pulse_widths_1
)

def test_can_land_at_0_degrees():
bg.set_angles(0, 0)
assert (bg.angle_1, bg.angle_2) == (0, 0)
assert self.plotter.angles_to_pw_1(-90) == approx(1894, abs=1e-0)
assert self.plotter.angles_to_pw_2(90) == approx(1422, abs=1e-0)

assert self.plotter.hysteresis_correction_1 == approx(5.416666)
assert self.plotter.hysteresis_correction_2 == approx(-8.3)

def test_status_report():
bg.status()
assert self.plotter.get_pulse_widths() == (
approx(1054 + self.plotter.hysteresis_correction_1, abs=1e-0),
approx(617 + self.plotter.hysteresis_correction_2, abs=1e-0),
)
assert (self.plotter.angle_1, self.plotter.angle_2) == (0, 0)

0 comments on commit 1e8e2e7

Please sign in to comment.