Skip to content

Commit

Permalink
Starting to work on unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanperret committed Jun 28, 2024
1 parent c810fb8 commit fae77c5
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/main/python/main/ayab/tests/test_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def setUp(self):

def test__singlebed(self):
control = Control(self.parent, self.parent.engine)
control.pattern = Pattern(Image.new("P", (1, 3)), Config(Machine(0)), 2)
control.pattern = Pattern(
Image.new("P", (1, 3)), Config(Machine.KH910_KH950), 2
)
control.num_colors = 2
control.start_row = 0
control.inf_repeat = False
Expand All @@ -72,7 +74,7 @@ def test__singlebed(self):
def test__classic_ribber_2col(self):
control = Control(self.parent, self.parent.engine)
control.pattern = Pattern(
Image.new("P", (1, 5)), Config(Machine(0), Mode.CLASSIC_RIBBER), 2
Image.new("P", (1, 5)), Config(Machine.KH910_KH950, Mode.CLASSIC_RIBBER), 2
)
control.num_colors = 2
control.start_row = 0
Expand Down Expand Up @@ -101,7 +103,7 @@ def test__classic_ribber_2col(self):
def test__classic_ribber_multicol(self):
control = Control(self.parent, self.parent.engine)
control.pattern = Pattern(
Image.new("P", (1, 3)), Config(Machine(0), Mode.CLASSIC_RIBBER), 3
Image.new("P", (1, 3)), Config(Machine.KH910_KH950, Mode.CLASSIC_RIBBER), 3
)
control.num_colors = 3
control.start_row = 0
Expand Down Expand Up @@ -135,7 +137,9 @@ def test__classic_ribber_multicol(self):
def test__middlecolorstwice_ribber(self):
control = Control(self.parent, self.parent.engine)
control.pattern = Pattern(
Image.new("P", (1, 5)), Config(Machine(0), Mode.MIDDLECOLORSTWICE_RIBBER), 3
Image.new("P", (1, 5)),
Config(Machine.KH910_KH950, Mode.MIDDLECOLORSTWICE_RIBBER),
3,
)
control.mode = Mode.MIDDLECOLORSTWICE_RIBBER
control.num_colors = 3
Expand Down Expand Up @@ -177,7 +181,9 @@ def test__middlecolorstwice_ribber(self):
def test__heartofpluto_ribber(self):
control = Control(self.parent, self.parent.engine)
control.pattern = Pattern(
Image.new("P", (1, 5)), Config(Machine(0), Mode.HEARTOFPLUTO_RIBBER), 3
Image.new("P", (1, 5)),
Config(Machine.KH910_KH950, Mode.HEARTOFPLUTO_RIBBER),
3,
)
control.mode = Mode.HEARTOFPLUTO_RIBBER
control.num_colors = 3
Expand Down Expand Up @@ -219,7 +225,7 @@ def test__heartofpluto_ribber(self):
def test__circular_ribber(self):
control = Control(self.parent, self.parent.engine)
control.pattern = Pattern(
Image.new("P", (1, 3)), Config(Machine(0), Mode.CIRCULAR_RIBBER), 3
Image.new("P", (1, 3)), Config(Machine.KH910_KH950, Mode.CIRCULAR_RIBBER), 3
)
control.num_colors = 3
control.start_row = 0
Expand Down Expand Up @@ -252,29 +258,28 @@ def test__circular_ribber(self):

def test_select_needles_API6(self):
control = Control(self.parent, self.parent.engine)
control.machine = Machine(0)
control.machine = Machine.KH910_KH950
control.num_colors = 2
control.start_row = 0

# 40 pixel image set to the left
control.mode = Mode.SINGLEBED
im = Image.new("P", (40, 3), 0)
im1 = Image.new("P", (40, 1), 1)
im.paste(im1, (0, 0))
pattern = Pattern(im, Config(Machine(0), Mode.SINGLEBED), 2)
pattern.alignment = Alignment.LEFT
im1 = Image.new("P", (10, 1), 1)
im.paste(im1, (10, 0))
pattern = Pattern(im, Config(Machine.KH910_KH950, Mode.SINGLEBED), 2)
pattern.alignment = Alignment.CENTER
control.pattern = pattern
assert pattern.pat_start_needle == 160
assert pattern.pat_end_needle == 200
control.start_needle = 160
control.end_needle = 200
assert (pattern.pat_start_needle, pattern.pat_end_needle) == (80, 120)
control.start_needle = 80
control.end_needle = 120
control.start_pixel = 0
control.end_pixel = 40
bits0 = bitarray()
bits0.frombytes(
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
expected = bitarray(
"00000000000000000000000000000000000000000000000000000000000000000000000000000000111111111100000000001111111111111111111100000000000000000000000000000000000000000000000000000000000000000000000000000000"
)
assert control.select_needles_API6(0, 0, False) == bits0
actual = control.select_needles_API6(0, 0, False)
assert actual == expected

def test_row_multiplier(self):
assert Mode.SINGLEBED.row_multiplier(2) == 1
Expand Down

0 comments on commit fae77c5

Please sign in to comment.