-
Notifications
You must be signed in to change notification settings - Fork 129
/
tests.py
executable file
·132 lines (91 loc) · 2.87 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from drawille import Canvas, line, Turtle
from unittest import TestCase, main
class CanvasTestCase(TestCase):
def test_set(self):
c = Canvas()
c.set(0, 0)
self.assertTrue(0 in c.chars and 0 in c.chars[0])
def test_unset_empty(self):
c = Canvas()
c.set(1, 1)
c.unset(1, 1)
self.assertEqual(len(c.chars), 0)
def test_unset_nonempty(self):
c = Canvas()
c.set(0, 0)
c.set(0, 1)
c.unset(0, 1)
self.assertEqual(c.chars[0][0], 1)
def test_clear(self):
c = Canvas()
c.set(1, 1)
c.clear()
self.assertEqual(c.chars, dict())
def test_toggle(self):
c = Canvas()
c.toggle(0, 0)
self.assertEqual(c.chars, {0: {0: 1}})
c.toggle(0, 0)
self.assertEqual(c.chars, dict())
def test_set_text(self):
c = Canvas()
c.set_text(0, 0, "asdf")
self.assertEqual(c.frame(), "asdf")
def test_frame(self):
c = Canvas()
self.assertEqual(c.frame(), '')
c.set(0, 0)
self.assertEqual(c.frame(), '⠁')
def test_max_min_limits(self):
c = Canvas()
c.set(0, 0)
self.assertEqual(c.frame(min_x=2), '')
self.assertEqual(c.frame(max_x=0), '')
def test_get(self):
c = Canvas()
self.assertEqual(c.get(0, 0), False)
c.set(0, 0)
self.assertEqual(c.get(0, 0), True)
self.assertEqual(c.get(0, 1), False)
self.assertEqual(c.get(1, 0), False)
self.assertEqual(c.get(1, 1), False)
class LineTestCase(TestCase):
def test_single_pixel(self):
self.assertEqual(list(line(0, 0, 0, 0)), [(0, 0)])
def test_row(self):
self.assertEqual(list(line(0, 0, 1, 0)), [(0, 0), (1, 0)])
def test_column(self):
self.assertEqual(list(line(0, 0, 0, 1)), [(0, 0), (0, 1)])
def test_diagonal(self):
self.assertEqual(list(line(0, 0, 1, 1)), [(0, 0), (1, 1)])
class TurtleTestCase(TestCase):
def test_position(self):
t = Turtle()
self.assertEqual(t.pos_x, 0)
self.assertEqual(t.pos_y, 0)
t.move(1, 1)
self.assertEqual(t.pos_x, 1)
self.assertEqual(t.pos_y, 1)
def test_rotation(self):
t = Turtle()
self.assertEqual(t.rotation, 0)
t.right(30)
self.assertEqual(t.rotation, 30)
t.left(30)
self.assertEqual(t.rotation, 0)
def test_brush(self):
t = Turtle()
self.assertFalse(t.get(t.pos_x, t.pos_y))
t.forward(1)
self.assertTrue(t.get(0, 0))
self.assertTrue(t.get(t.pos_x, t.pos_y))
t.up()
t.move(2, 0)
self.assertFalse(t.get(t.pos_x, t.pos_y))
t.down()
t.move(3, 0)
self.assertTrue(t.get(t.pos_x, t.pos_y))
if __name__ == '__main__':
main()