From aa1595c734a1bd75b52e5f75bf5a8b5cae2e498a Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 2 Oct 2021 21:49:55 +0200 Subject: Refactoring --- tests/field.nim | 220 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/testField.nim | 220 ---------------------------------------------------- 2 files changed, 220 insertions(+), 220 deletions(-) create mode 100644 tests/field.nim delete mode 100644 tests/testField.nim diff --git a/tests/field.nim b/tests/field.nim new file mode 100644 index 0000000..8d5a1dc --- /dev/null +++ b/tests/field.nim @@ -0,0 +1,220 @@ +import unittest + +include ../src/field + +func `==`(a, b: Line): bool = a.x == b.x and a.l == b.l and a.columns == b.columns +func `==`(a, b: Field): bool = a.x == b.x and a.lx == b.lx and a.y == b.y and a.ly == b.ly and a.lines == b.lines +func cols(a: openarray[char]): seq[int] = + result.setlen(a.len) + for i in 0..', ':', '#', ',', '_', '@'].cols)]) + check hello1A.load("examples/hello.b98") == true + check hello1A == hello1B + var rn: Field + check rn.load("examples/rn.b98") == true + check rn == hello1B + var hello2A: Field; var hello2B = Field(x: 1, lx: 33, ly: 2,lines: @[ + Line(x:33, l:1, columns: @['v'].cols), + Line(x:1, l:33, columns: @['@', ' ', '>', ' ', '#', ';', '>', ':', '#', ',', '_', 'e', '-', 'j', ';', ' ', '"', 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', '"', 'd', 'a', '<'].cols) + ]) + check hello2A.load("examples/hello2.b98") == true + check hello2A == hello2B + var factorial2A: Field; var factorial2B = Field(x: 0, lx: 15, ly: 2,lines: @[ + Line(x:0, l:15, columns: @['&', '>', ':', '1', '-', ':', 'v', ' ', 'v', ' ', '*', '_', '$', '.', '@'].cols), + Line(x:1, l:11, columns: @['^', ' ', ' ', ' ', ' ', '_', '$', '>', '\\', ':', '^'].cols) + ]) + check factorial2A.load("examples/factorial.b98") == true + check factorial2A == factorial2B + var dna2A: Field; var dna2B = Field(x: 0, lx: 7, ly: 8,lines: @[ + Line(x:0, l:7, columns: @['7', '^', 'D', 'N', '>', 'v', 'A'].cols), + Line(x:0, l:7, columns: @['v', '_', '#', 'v', '?', ' ', 'v'].cols), + Line(x:0, l:7, columns: @['7', '^', '<', '"', '"', '"', '"'].cols), + Line(x:0, l:7, columns: @['3', ' ', ' ', 'A', 'C', 'G', 'T'].cols), + Line(x:0, l:7, columns: @['9', '0', '!', '"', '"', '"', '"'].cols), + Line(x:0, l:7, columns: @['4', '*', ':', '>', '>', '>', 'v'].cols), + Line(x:0, l:7, columns: @['+', '8', '^', '-', '1', ',', '<'].cols), + Line(x:0, l:7, columns: @['>', ' ', ',', '+', ',', '@', ')'].cols), + ]) + check dna2A.load("examples/dna.b98") == true + check dna2A == dna2B + test "set": + var f = Field(x: 0, y: 0, lx: 1, ly: 1, lines: @[Line(x: 0, l: 1, columns: @['>'].cols)]) + f.set(0,0,int('@')) + check f == minimal + f.set(1,0,int(' ')) + check f == minimal + const xappend = Field(x: 0, y: 0, lx: 5, ly: 1, lines: @[Line(x: 0, l: 5, columns: @[int('@'), 32, 32, 32, int('r')])]) + f.set(4, 0, int('r')) + check f == xappend + const xprepend = Field(x: -2, y: 0, lx: 7, ly: 1, lines: @[Line(x: -2, l: 7, columns: @[int('l'), 32, int('@'), 32, 32, 32, int('r')])]) + f.set(-2, 0, int('l')) + check f == xprepend + const yappend = Field(x: -2, y: 0, lx: 8, ly: 3, lines: @[ + Line(x: -2, l: 7, columns: @[int('l'), 32, int('@'), 32, 32, 32, int('r')]), + Line(x: 0, l: 0, columns: @[]), + Line(x: 5, l: 1, columns: @[int('d')]), + ]) + f.set(5, 2, int('d')) + check f == yappend + const yprepend = Field(x: -2, y: -3, lx: 11, ly: 6, lines: @[ + Line(x: 8, l: 1, columns: @[int('u')]), + Line(x: 0, l: 0, columns: @[]), + Line(x: 0, l: 0, columns: @[]), + Line(x: -2, l: 7, columns: @[int('l'), 32, int('@'), 32, 32, 32, int('r')]), + Line(x: 0, l: 0, columns: @[]), + Line(x: 5, l: 1, columns: @[int('d')]), + ]) + f.set(8, -3, int('u')) + check f == yprepend + const xappendEmptyline = Field(x: -2, y: -3, lx: 12, ly: 6, lines: @[ + Line(x: 8, l: 1, columns: @[int('u')]), + Line(x: 9, l: 1, columns: @[int('e')]), + Line(x: 0, l: 0, columns: @[]), + Line(x: -2, l: 7, columns: @[int('l'), 32, int('@'), 32, 32, 32, int('r')]), + Line(x: 0, l: 0, columns: @[]), + Line(x: 5, l: 1, columns: @[int('d')]), + ]) + f.set(9, -2, int('e')) + check f == xappendEmptyline + const xprependEmptyline = Field(x: -3, y: -3, lx: 13, ly: 6, lines: @[ + Line(x: 8, l: 1, columns: @[int('u')]), + Line(x: 9, l: 1, columns: @[int('e')]), + Line(x: 0, l: 0, columns: @[]), + Line(x: -2, l: 7, columns: @[int('l'), 32, int('@'), 32, 32, 32, int('r')]), + Line(x: -3, l: 1, columns: @[int('f')]), + Line(x: 5, l: 1, columns: @[int('d')]), + ]) + f.set(-3, 1, int('f')) + check f == xprependEmptyline + const xprependyprepend = Field(x: -5, y: -5, lx: 15, ly: 8, lines: @[ + Line(x: -5, l: 1, columns: @[int('x')]), + Line(x: 0, l: 0, columns: @[]), + Line(x: 8, l: 1, columns: @[int('u')]), + Line(x: 9, l: 1, columns: @[int('e')]), + Line(x: 0, l: 0, columns: @[]), + Line(x: -2, l: 7, columns: @[int('l'), 32, int('@'), 32, 32, 32, int('r')]), + Line(x: -3, l: 1, columns: @[int('f')]), + Line(x: 5, l: 1, columns: @[int('d')]), + ]) + f.set(-5, -5, int('x')) + check f == xprependyprepend + const xprependyappend = Field(x: -7, y: -5, lx: 17, ly: 10, lines: @[ + Line(x: -5, l: 1, columns: @[int('x')]), + Line(x: 0, l: 0, columns: @[]), + Line(x: 8, l: 1, columns: @[int('u')]), + Line(x: 9, l: 1, columns: @[int('e')]), + Line(x: 0, l: 0, columns: @[]), + Line(x: -2, l: 7, columns: @[int('l'), 32, int('@'), 32, 32, 32, int('r')]), + Line(x: -3, l: 1, columns: @[int('f')]), + Line(x: 5, l: 1, columns: @[int('d')]), + Line(x: 0, l: 0, columns: @[]), + Line(x: -7, l: 1, columns: @[int('y')]), + ]) + f.set(-7, 4, int('y')) + check f == xprependyappend diff --git a/tests/testField.nim b/tests/testField.nim deleted file mode 100644 index c1def19..0000000 --- a/tests/testField.nim +++ /dev/null @@ -1,220 +0,0 @@ -import unittest - -include field - -func `==`(a, b: Line): bool = a.x == b.x and a.l == b.l and a.columns == b.columns -func `==`(a, b: Field): bool = a.x == b.x and a.lx == b.lx and a.y == b.y and a.ly == b.ly and a.lines == b.lines -func cols(a: openarray[char]): seq[int] = - result.setlen(a.len) - for i in 0..', ':', '#', ',', '_', '@'].cols)]) - check hello1A.load("examples/hello.b98") == true - check hello1A == hello1B - var rn: Field - check rn.load("examples/rn.b98") == true - check rn == hello1B - var hello2A: Field; var hello2B = Field(x: 1, lx: 33, ly: 2,lines: @[ - Line(x:33, l:1, columns: @['v'].cols), - Line(x:1, l:33, columns: @['@', ' ', '>', ' ', '#', ';', '>', ':', '#', ',', '_', 'e', '-', 'j', ';', ' ', '"', 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', '"', 'd', 'a', '<'].cols) - ]) - check hello2A.load("examples/hello2.b98") == true - check hello2A == hello2B - var factorial2A: Field; var factorial2B = Field(x: 0, lx: 15, ly: 2,lines: @[ - Line(x:0, l:15, columns: @['&', '>', ':', '1', '-', ':', 'v', ' ', 'v', ' ', '*', '_', '$', '.', '@'].cols), - Line(x:1, l:11, columns: @['^', ' ', ' ', ' ', ' ', '_', '$', '>', '\\', ':', '^'].cols) - ]) - check factorial2A.load("examples/factorial.b98") == true - check factorial2A == factorial2B - var dna2A: Field; var dna2B = Field(x: 0, lx: 7, ly: 8,lines: @[ - Line(x:0, l:7, columns: @['7', '^', 'D', 'N', '>', 'v', 'A'].cols), - Line(x:0, l:7, columns: @['v', '_', '#', 'v', '?', ' ', 'v'].cols), - Line(x:0, l:7, columns: @['7', '^', '<', '"', '"', '"', '"'].cols), - Line(x:0, l:7, columns: @['3', ' ', ' ', 'A', 'C', 'G', 'T'].cols), - Line(x:0, l:7, columns: @['9', '0', '!', '"', '"', '"', '"'].cols), - Line(x:0, l:7, columns: @['4', '*', ':', '>', '>', '>', 'v'].cols), - Line(x:0, l:7, columns: @['+', '8', '^', '-', '1', ',', '<'].cols), - Line(x:0, l:7, columns: @['>', ' ', ',', '+', ',', '@', ')'].cols), - ]) - check dna2A.load("examples/dna.b98") == true - check dna2A == dna2B - test "Field.set": - var f = Field(x: 0, y: 0, lx: 1, ly: 1, lines: @[Line(x: 0, l: 1, columns: @['>'].cols)]) - f.set(0,0,int('@')) - check f == minimal - f.set(1,0,int(' ')) - check f == minimal - const xappend = Field(x: 0, y: 0, lx: 5, ly: 1, lines: @[Line(x: 0, l: 5, columns: @[int('@'), 32, 32, 32, int('r')])]) - f.set(4, 0, int('r')) - check f == xappend - const xprepend = Field(x: -2, y: 0, lx: 7, ly: 1, lines: @[Line(x: -2, l: 7, columns: @[int('l'), 32, int('@'), 32, 32, 32, int('r')])]) - f.set(-2, 0, int('l')) - check f == xprepend - const yappend = Field(x: -2, y: 0, lx: 8, ly: 3, lines: @[ - Line(x: -2, l: 7, columns: @[int('l'), 32, int('@'), 32, 32, 32, int('r')]), - Line(x: 0, l: 0, columns: @[]), - Line(x: 5, l: 1, columns: @[int('d')]), - ]) - f.set(5, 2, int('d')) - check f == yappend - const yprepend = Field(x: -2, y: -3, lx: 11, ly: 6, lines: @[ - Line(x: 8, l: 1, columns: @[int('u')]), - Line(x: 0, l: 0, columns: @[]), - Line(x: 0, l: 0, columns: @[]), - Line(x: -2, l: 7, columns: @[int('l'), 32, int('@'), 32, 32, 32, int('r')]), - Line(x: 0, l: 0, columns: @[]), - Line(x: 5, l: 1, columns: @[int('d')]), - ]) - f.set(8, -3, int('u')) - check f == yprepend - const xappendEmptyline = Field(x: -2, y: -3, lx: 12, ly: 6, lines: @[ - Line(x: 8, l: 1, columns: @[int('u')]), - Line(x: 9, l: 1, columns: @[int('e')]), - Line(x: 0, l: 0, columns: @[]), - Line(x: -2, l: 7, columns: @[int('l'), 32, int('@'), 32, 32, 32, int('r')]), - Line(x: 0, l: 0, columns: @[]), - Line(x: 5, l: 1, columns: @[int('d')]), - ]) - f.set(9, -2, int('e')) - check f == xappendEmptyline - const xprependEmptyline = Field(x: -3, y: -3, lx: 13, ly: 6, lines: @[ - Line(x: 8, l: 1, columns: @[int('u')]), - Line(x: 9, l: 1, columns: @[int('e')]), - Line(x: 0, l: 0, columns: @[]), - Line(x: -2, l: 7, columns: @[int('l'), 32, int('@'), 32, 32, 32, int('r')]), - Line(x: -3, l: 1, columns: @[int('f')]), - Line(x: 5, l: 1, columns: @[int('d')]), - ]) - f.set(-3, 1, int('f')) - check f == xprependEmptyline - const xprependyprepend = Field(x: -5, y: -5, lx: 15, ly: 8, lines: @[ - Line(x: -5, l: 1, columns: @[int('x')]), - Line(x: 0, l: 0, columns: @[]), - Line(x: 8, l: 1, columns: @[int('u')]), - Line(x: 9, l: 1, columns: @[int('e')]), - Line(x: 0, l: 0, columns: @[]), - Line(x: -2, l: 7, columns: @[int('l'), 32, int('@'), 32, 32, 32, int('r')]), - Line(x: -3, l: 1, columns: @[int('f')]), - Line(x: 5, l: 1, columns: @[int('d')]), - ]) - f.set(-5, -5, int('x')) - check f == xprependyprepend - const xprependyappend = Field(x: -7, y: -5, lx: 17, ly: 10, lines: @[ - Line(x: -5, l: 1, columns: @[int('x')]), - Line(x: 0, l: 0, columns: @[]), - Line(x: 8, l: 1, columns: @[int('u')]), - Line(x: 9, l: 1, columns: @[int('e')]), - Line(x: 0, l: 0, columns: @[]), - Line(x: -2, l: 7, columns: @[int('l'), 32, int('@'), 32, 32, 32, int('r')]), - Line(x: -3, l: 1, columns: @[int('f')]), - Line(x: 5, l: 1, columns: @[int('d')]), - Line(x: 0, l: 0, columns: @[]), - Line(x: -7, l: 1, columns: @[int('y')]), - ]) - f.set(-7, 4, int('y')) - check f == xprependyappend -- cgit v1.2.3