-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasy_homework-006_spec.rb
77 lines (65 loc) · 2.38 KB
/
easy_homework-006_spec.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
# Create our dice throwing app consisting of classes interacting with each other.
# Hard: write everything from scratch including tests
# Medium: pull the tests write the two classes yourself
# Easy use more information to solve the problem
# What classes do we need? How do they interact with each other?
# Write the tests for these classes. What types of tests do we need? Write tests for each class.
# For each class, test all public methods. Also test the creating of on instance of the class.
# Input you test should be: empty input, standard input, wrong input.
# In addition think about edge cases.
# To summarize the app functionality, we want to have:
# - user interface (command prompt)
# - creating a single Dice
# - rolling a single Dice
# - roll all dices we have for our DiceGame
# - display the result for each dice
# What classes do make most sense
# Create the tests first. If you don't feel comfortable with creating tests yourself you can
# pull them here.
# If you need additional hints, you find them here.
# If you're still stuck. You can find a basic structure here.
require_relative 'warmup-006'
describe "Die" do
die = Die.new
die2 = Die.new(sides: 10)
die3 = Die.new(sides: "human")
it "has 4 sides if no sides supplied" do
expect(die.sides).to eq(4)
end
it "has sides" do
expect(die2.sides).to eq(10)
end
it "has no face after creation" do
expect(die.face).to be_nil
end
it "has a face after it's rolled" do
expect(die.roll).to be_between(1, die.sides)
expect(die.face).to be_between(1, die.sides)
end
it "tells face and sides" do
die2.face = 7
expect(die2.tell_properties).to eq("The die has face 7 and 10 sides.\n")
end
end
describe "DiceGame" do
dice_game = DiceGame.new
it "has no dies" do
expect(dice_game.dies).to be_empty
end
it "tells that the game has no dies yet" do
expect(dice_game.on_the_table).to eq("No dies were added to the game, yet.")
end
it "adds a die" do
dice_game.add_die(20)
expect(dice_game.dies.find { |die| die.sides == 20 }).to_not be_nil
end
it "tells the properties of all dies" do
dice_game.add_die(30)
dice_game.add_die(14)
expect(dice_game.on_the_table).to eq(dice_game.dies.map(&:tell_properties).join)
end
it "has been rolled and all dies have faces" do
dice_game.roll_all
expect(dice_game.dies.all? { |die| die.face }).to be_truthy
end
end