-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver_test.rb
90 lines (76 loc) · 2.87 KB
/
driver_test.rb
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
require "minitest/autorun"
require_relative "driver"
class DriverTest < Minitest::Test
def setup
@d = Driver::new("Driver 1")
end
# UNIT TESTS FOR METHOD add_book
# There are no parameters, it does not make sense to partition it.
# This test ensures that when a book is added, the number of books increases by 1.
def test_add_book
@d.add_book
assert_equal @d.books, 1
@d.add_book
assert_equal @d.books, 2
end
# UNIT TESTS FOR METHOD add_dino
# There are no parameters, it does not make sense to partition it.
# This test ensures that when a dino is added, the number of dinos increases by 1.
def test_add_dino
@d.add_dino
assert_equal @d.dinos, 1
@d.add_dino
assert_equal @d.dinos, 2
end
# UNIT TESTS FOR METHOD add_class
# There are no parameters, it does not make sense to partition it.
# This test ensures that when a class is added, the number of dinos multiplies by 2.
def test_add_class
assert_equal @d.classes, 1
@d.add_class
assert_equal @d.classes, 2
@d.add_class
assert_equal @d.classes, 4
end
# UNIT TESTS FOR METHOD pluralize(singularStr, num)
# Equivalence classes:
# num = 0 && singularStr ends with s -> returns "#{singularStr}es"
# num = 0 && singularStr does not end with s -> returns "#{singularStr}s"
# num = 1 -> returns singularStr
# num = 2..INFINITY && singularStr ends with s -> returns "#{singularStr}es"
# num = 2..INFINITY && singularStr does not end with s -> returns "#{singularStr}s"
# num = 0 && singularStr ends with s -> returns "#{singularStr}es"
# 0 classes should return "classes"
def test_pluralize_zero_ends_s
assert_equal "classes", @d.pluralize("class", 0)
end
# num = 0 && singularStr does not end with s -> returns "#{singularStr}s"
# 0 books should return "books"
def test_pluralize_zero_not_ends_s
assert_equal "books", @d.pluralize("book", 0)
end
# num = 1 -> returns singularStr
# 1 book should return "book"
def test_pluralize_one
assert_equal "book", @d.pluralize("book", 1)
end
# num = 2..INFINITY && singularStr ends with s -> returns "#{singularStr}es"
# 2 classes should return "classes"
def test_pluralize_two_ends_s
assert_equal "classes", @d.pluralize("class", 2)
end
# num = 2..INFINITY && singularStr does not end with s -> returns "#{singularStr}s"
# 2 books should return "books"
def test_pluralize_two_not_ends_s
assert_equal "books", @d.pluralize("book", 2)
end
# UNIT TESTS FOR METHOD print_results
# There are no parameters, it does not make sense to partition it.
# This test ensures the proper output with arbitrary values assigned to books, dinos, & classes.
def test_print_results
@d.books = 6
@d.dinos = 11
@d.classes = 4
assert_output("Driver 1 obtained 6 books!\nDriver 1 obtained 11 dinosaur toys!\nDriver 1 attended 4 classes!\n") { @d.print_results }
end
end