-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_pencil.py
70 lines (58 loc) · 3.04 KB
/
test_pencil.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
import unittest
from pencil import Pencil
class TestPencil(unittest.TestCase):
def test_aPencilWithSufficientlyDurablePointCanWrite(self):
p = Pencil(length = 40, pointDurability = 1000, eraserDurability = 200)
text = "Four score and seven years ago"
p.write(text)
self.assertTrue(p.getText() == text)
def test_aPencilWritesBlanksAfterPointLosesDurability(self):
p = Pencil(length = 40, pointDurability = 4, eraserDurability = 200)
p.write("ambidextrous")
self.assertTrue(p.getText() == "ambi ")
def test_aSharpenedPencilCanWriteAgain(self):
p = Pencil(length = 40, pointDurability = 4, eraserDurability = 200)
p.write("ambi")
p.sharpen()
p.write("dextrous")
self.assertTrue(p.getText() == "ambidext ")
def test_erasingTextReplacesItsLastOccurrenceWithSpaces(self):
p = Pencil(length = 40, pointDurability = 1000, eraserDurability = 200)
p.write("last on last night's schedule was immigration law")
p.erase("la")
self.assertTrue(p.getText() == "last on last night's schedule was immigration w")
p.erase("la")
self.assertTrue(p.getText() == "last on st night's schedule was immigration w")
def test_erasersWearOut(self):
p = Pencil(length = 40, pointDurability = 1000, eraserDurability = 2)
p.write("last on last night's schedule was immigration law")
p.erase("la")
self.assertTrue(p.getText() == "last on last night's schedule was immigration w")
p.erase("la")
self.assertTrue(p.getText() == "last on last night's schedule was immigration w")
def test_textIsErasedFromTheRight(self):
p = Pencil(length = 40, pointDurability = 1000, eraserDurability = 5)
p.write("a Kafkaesque bureaucracy")
p.erase("Kafkaesque")
self.assertTrue(p.getText() == "a Kafka bureaucracy")
def test_whitespaceDoesntDepleteErasers(self):
p = Pencil(length = 40, pointDurability = 1000, eraserDurability = 5)
p.write("last on last night's schedule was immigration law")
p.erase(" was ")
self.assertTrue(p.getText() == "last on last night's schedule immigration law")
p.erase("la")
self.assertTrue(p.getText() == "last on last night's schedule immigration w")
def test_editingOverwritesErasedText(self):
p = Pencil(length = 40, pointDurability = 1000, eraserDurability = 200)
p.write("An apple a day keeps the doctor away")
p.erase("apple")
p.overwrite("onion")
self.assertTrue(p.getText() == "An onion a day keeps the doctor away")
def test_editingMarksCollisionsWithNonSpaceWithAt(self):
p = Pencil(length = 40, pointDurability = 1000, eraserDurability = 200)
p.write("An apple a day keeps the doctor away")
p.erase("apple")
p.overwrite("artichoke")
self.assertTrue(p.getText() == "An artich@k@ay keeps the doctor away")
if __name__ == '__main__':
unittest.main()