Skip to content

Commit deac5fb

Browse files
committed
add segment_quadratic_curve unit tests
1 parent 1774ae6 commit deac5fb

File tree

1 file changed

+127
-5
lines changed

1 file changed

+127
-5
lines changed

tests/test_stringbuilder.py

Lines changed: 127 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def mock_isatty():
287287
coord1 = Coordinate(0, 0, True, False, False, False)
288288
coord2 = Coordinate(1, 1, True, False, False, False)
289289
res = pathins.stringbuilder.segment_line(coord1, coord2, 1.0, nocolor=False)
290-
assert res == "(0,0) (1,1): \033[1;96mLINE\033[0m 1.00 units"
290+
assert res == "(0,0) (1,1): \033[1;96mLINE\033[0m 1.00 units"
291291

292292

293293
def test_segment_line_with_coord1_startpoint_color(monkeypatch):
@@ -301,7 +301,7 @@ def mock_isatty():
301301
coord1 = Coordinate(0, 0, True, True, False, False)
302302
coord2 = Coordinate(1, 1, True, False, False, False)
303303
res = pathins.stringbuilder.segment_line(coord1, coord2, 1.0, nocolor=False)
304-
assert res == "\033[32m(0,0)\033[0m (1,1): \033[1;96mLINE\033[0m 1.00 units"
304+
assert res == "\033[32m(0,0)\033[0m (1,1): \033[1;96mLINE\033[0m 1.00 units"
305305

306306

307307
def test_segment_line_with_coord2_startpoint_color(monkeypatch):
@@ -315,7 +315,7 @@ def mock_isatty():
315315
coord1 = Coordinate(0, 0, True, False, False, False)
316316
coord2 = Coordinate(1, 1, True, True, False, False)
317317
res = pathins.stringbuilder.segment_line(coord1, coord2, 1.0, nocolor=False)
318-
assert res == "(0,0) \033[32m(1,1)\033[0m: \033[1;96mLINE\033[0m 1.00 units"
318+
assert res == "(0,0) \033[32m(1,1)\033[0m: \033[1;96mLINE\033[0m 1.00 units"
319319

320320

321321
def test_segment_line_with_endpoint_color(monkeypatch):
@@ -329,7 +329,7 @@ def mock_isatty():
329329
coord1 = Coordinate(0, 0, True, False, True, False)
330330
coord2 = Coordinate(1, 1, True, False, False, False)
331331
res = pathins.stringbuilder.segment_line(coord1, coord2, 1.0, nocolor=False)
332-
assert res == "\033[31m(0,0)\033[0m (1,1): \033[1;96mLINE\033[0m 1.00 units"
332+
assert res == "\033[31m(0,0)\033[0m (1,1): \033[1;96mLINE\033[0m 1.00 units"
333333

334334

335335
def test_segment_line_with_nocolor(monkeypatch):
@@ -343,4 +343,126 @@ def mock_isatty():
343343
coord1 = Coordinate(0, 0, True, False, True, False)
344344
coord2 = Coordinate(1, 1, True, False, False, False)
345345
res = pathins.stringbuilder.segment_line(coord1, coord2, 1.0, nocolor=True)
346-
assert res == "(0,0) (1,1): LINE 1.00 units"
346+
assert res == "(0,0) (1,1): LINE 1.00 units"
347+
348+
349+
def test_segment_quadratic_curve_default(monkeypatch):
350+
# mock tty
351+
def mock_isatty():
352+
return True
353+
354+
# apply the monkeypatch for sys.stdout.isatty()
355+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
356+
357+
coord1 = Coordinate(0, 0, True, False, False, False)
358+
coord2 = Coordinate(1, 1, False, False, False, False)
359+
coord3 = Coordinate(2, 2, True, False, False, False)
360+
res = pathins.stringbuilder.segment_quadratic_curve(
361+
coord1, coord2, coord3, 1.0, nocolor=False
362+
)
363+
assert res == "(0,0) (1,1) (2,2): \033[1;96mQCURVE\033[0m 1.00 units"
364+
365+
366+
def test_segment_quadratic_curve_coord1_startpoint(monkeypatch):
367+
# mock tty
368+
def mock_isatty():
369+
return True
370+
371+
# apply the monkeypatch for sys.stdout.isatty()
372+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
373+
374+
coord1 = Coordinate(0, 0, True, True, False, False)
375+
coord2 = Coordinate(1, 1, False, False, False, False)
376+
coord3 = Coordinate(2, 2, True, False, False, False)
377+
res = pathins.stringbuilder.segment_quadratic_curve(
378+
coord1, coord2, coord3, 1.0, nocolor=False
379+
)
380+
assert res == "\033[32m(0,0)\033[0m (1,1) (2,2): \033[1;96mQCURVE\033[0m 1.00 units"
381+
382+
383+
def test_segment_quadratic_curve_coord3_startpoint(monkeypatch):
384+
# mock tty
385+
def mock_isatty():
386+
return True
387+
388+
# apply the monkeypatch for sys.stdout.isatty()
389+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
390+
391+
coord1 = Coordinate(0, 0, True, False, False, False)
392+
coord2 = Coordinate(1, 1, False, False, False, False)
393+
coord3 = Coordinate(2, 2, True, True, False, False)
394+
res = pathins.stringbuilder.segment_quadratic_curve(
395+
coord1, coord2, coord3, 1.0, nocolor=False
396+
)
397+
assert res == "(0,0) (1,1) \033[32m(2,2)\033[0m: \033[1;96mQCURVE\033[0m 1.00 units"
398+
399+
400+
def test_segment_quadratic_curve_coord1_endpoint(monkeypatch):
401+
# mock tty
402+
def mock_isatty():
403+
return True
404+
405+
# apply the monkeypatch for sys.stdout.isatty()
406+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
407+
408+
coord1 = Coordinate(0, 0, True, False, True, False)
409+
coord2 = Coordinate(1, 1, False, False, False, False)
410+
coord3 = Coordinate(2, 2, True, False, False, False)
411+
res = pathins.stringbuilder.segment_quadratic_curve(
412+
coord1, coord2, coord3, 1.0, nocolor=False
413+
)
414+
assert res == "\033[31m(0,0)\033[0m (1,1) (2,2): \033[1;96mQCURVE\033[0m 1.00 units"
415+
416+
417+
def test_segment_quadratic_curve_coord3_endpoint(monkeypatch):
418+
# mock tty
419+
def mock_isatty():
420+
return True
421+
422+
# apply the monkeypatch for sys.stdout.isatty()
423+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
424+
425+
coord1 = Coordinate(0, 0, True, False, False, False)
426+
coord2 = Coordinate(1, 1, False, False, False, False)
427+
coord3 = Coordinate(2, 2, True, False, True, False)
428+
res = pathins.stringbuilder.segment_quadratic_curve(
429+
coord1, coord2, coord3, 1.0, nocolor=False
430+
)
431+
assert res == "(0,0) (1,1) \033[31m(2,2)\033[0m: \033[1;96mQCURVE\033[0m 1.00 units"
432+
433+
434+
def test_segment_quadratic_curve_coord2_coord3_endpoint_startpoint(monkeypatch):
435+
# mock tty
436+
def mock_isatty():
437+
return True
438+
439+
# apply the monkeypatch for sys.stdout.isatty()
440+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
441+
442+
coord1 = Coordinate(0, 0, True, False, False, False)
443+
coord2 = Coordinate(1, 1, False, False, True, False)
444+
coord3 = Coordinate(2, 2, True, True, False, False)
445+
res = pathins.stringbuilder.segment_quadratic_curve(
446+
coord1, coord2, coord3, 1.0, nocolor=False
447+
)
448+
assert (
449+
res
450+
== "(0,0) \033[31m(1,1)\033[0m \033[32m(2,2)\033[0m: \033[1;96mQCURVE\033[0m 1.00 units"
451+
)
452+
453+
454+
def test_segment_quadratic_curve_nocolor_default(monkeypatch):
455+
# mock tty
456+
def mock_isatty():
457+
return True
458+
459+
# apply the monkeypatch for sys.stdout.isatty()
460+
monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty)
461+
462+
coord1 = Coordinate(0, 0, True, False, False, False)
463+
coord2 = Coordinate(1, 1, False, False, True, False)
464+
coord3 = Coordinate(2, 2, True, True, False, False)
465+
res = pathins.stringbuilder.segment_quadratic_curve(
466+
coord1, coord2, coord3, 1.0, nocolor=True
467+
)
468+
assert res == "(0,0) (1,1) (2,2): QCURVE 1.00 units"

0 commit comments

Comments
 (0)