-
Notifications
You must be signed in to change notification settings - Fork 0
/
cube_tests.py
90 lines (76 loc) · 2.52 KB
/
cube_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
from classes.point import Point
from classes.direction import Direction
from classes.cube import Cube
from copy import deepcopy
# Fill works
cube = Cube()
cube.fillPoint(Point(1, 1, 1))
cube.fillPoint(Point(2, 2, 2))
cube.shift(Direction.right)
assert(cube.filled_points == set([Point(2, 1, 1), Point(3, 2, 2)]))
# isValid works
cube = Cube()
assert(cube.isValid())
cube.fillPoint(Point(4, 0, 0))
assert(not cube.isValid())
# pointIsValid works
cube = Cube()
assert(cube.pointIsValid(Point(0, 0, 0)))
assert(not cube.pointIsValid(Point(4, 0, 0)))
assert(not cube.pointIsValid(Point(0, 0, -1)))
# pointIsFilled works
cube = Cube()
cube.fillPoint(Point(1, 1, 1))
assert(cube.pointIsFilled(Point(1, 1, 1)))
assert(not cube.pointIsFilled(Point(0, 0, 0)))
# fillDirection works with first insert
cube = Cube()
cube.fillDirection(Direction.right)
assert(cube.current_point == Point(0, 0, 0))
assert(cube.filled_points == set([Point(0, 0, 0)]))
# fillDirection works without shift
cube = Cube()
cube.fillDirection(Direction.right)
cube.fillDirection(Direction.right)
assert(cube.current_point == Point(1, 0, 0))
assert(cube.filled_points == set([Point(0, 0, 0), Point(1, 0, 0)]))
# fillDirection works with basic shift
cube = Cube()
cube.fillDirection(Direction.away)
cube.fillDirection(Direction.left)
assert(cube.isValid())
assert(cube.filled_points == set([Point(1, 0, 0), Point(0, 0, 0)]))
# fillDirection works over time...
cube = Cube()
cube.fillDirection(Direction.right)
cube.fillDirection(Direction.right)
cube.fillDirection(Direction.right)
cube.fillDirection(Direction.right)
assert(cube.isValid())
assert(cube.current_point == Point(3, 0, 0))
assert(cube.filled_points == set([Point(0, 0, 0), Point(1, 0, 0), Point(2, 0, 0), Point(3, 0, 0)]))
# but fails when it goes over the side
cube.fillDirection(Direction.right)
assert(not cube.isValid())
# fillDirection works in multiple directions...
cube = Cube()
cube.fillDirection(Direction.away)
cube.fillDirection(Direction.right)
cube.fillDirection(Direction.up)
cube.fillDirection(Direction.left)
assert(cube.isValid())
assert(cube.current_point == Point(0, 1, 0))
assert(cube.filled_points == set([Point(0, 0, 0), Point(1, 0, 0), Point(1, 1, 0), Point(0, 1, 0)]))
# but fails when it runs into itself
cube.fillDirection(Direction.down)
assert(not cube.isValid())
# copy works
cube = Cube()
cube_2 = cube
cube_2.fillPoint(Point(1, 1, 1))
assert(cube.pointIsFilled(Point(1, 1, 1)))
cube = Cube()
cube_2 = deepcopy(cube)
cube_2.fillPoint(Point(1, 1, 1))
assert(not cube.pointIsFilled(Point(1, 1, 1)))
print("SUCCESS")