-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhealth_log_test.rb
156 lines (138 loc) · 3.72 KB
/
health_log_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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
gem 'minitest'
require 'minitest/autorun'
require 'minitest/pride'
require 'pathname'
require_relative 'health_log'
class HealthLogTest < MiniTest::Test
def setup
@file = "test.yml"
@log = HealthLog.new @file, config_file: 'test_config.yml'
@date = Date.today.to_s
end
def teardown
fixture_file = Pathname('fixture.yml')
fixture_file.delete if fixture_file.exist?
test_file = Pathname(@file)
test_file.delete if test_file.exist?
end
def test_adding_an_entry
@log.entry sample_input
actual = File.read @file
assert_equal expected_output.to_yaml, actual
end
def test_add_partial_data
@log.entry sample_input
@log.entry "bf: partial entry"
expected = expected_output
expected[@date][:'bad food'] = "partial entry"
actual = File.read @file
assert_equal expected.to_yaml, actual
end
def test_appending_data_to_field
@log.entry sample_input
log = HealthLog.new @file, config_file: 'test_config.yml'
log.entry "x: partial entry"
expected = expected_output
expected[@date][:exercise] += ". partial entry"
actual = File.read @file
assert_equal expected.to_yaml, actual
end
def test_handles_empty_input
@log.entry sample_input
@log.entry "\n"
actual = File.read @file
assert_equal expected_output.to_yaml, actual
end
def test_graph
weights = { Date.today.to_s => { weight: 199.5 },
(Date.today - 1).to_s => { weight: 198.0},
(Date.today - 2).to_s => { weight: 192 }
}.to_yaml
File.open('fixture.yml', 'w') { |f| f.write weights }
log = HealthLog.new 'fixture.yml'
expected = [
'+' * 45,
'+' * 30,
'-' * 30,
].reverse
assert_equal expected, log.graph(3)
end
def test_graph_with_missing_days
weights = { Date.today.to_s => { weight: 199.5 },
(Date.today - 2).to_s => { weight: 192 }
}.to_yaml
File.open('fixture.yml', 'w') { |f| f.write weights }
log = HealthLog.new 'fixture.yml'
expected = [
'+' * 45,
'',
'-' * 30,
].reverse
assert_equal expected, log.graph(3)
end
def test_reviewing_all_entries
end
def test_export_weights_to_csv
end
def test_exported_weights_inserts_missing_days
end
def test_report_for_last_n_days
expected = {
"#{Date.today.to_s}" => {
sleep: '6.5',
exercise: 'none, gym was closed',
diet: {
quality: '2 or 3 servings of sugar',
volume: 'not bad'
},
'belt loop' => '4'
},
"#{(Date.today - 1).to_s}" => {
results: '-'
},
"#{(Date.today - 2).to_s}" => {
sleep: '5.5',
exercise: 'great',
diet: {
quality: 'good',
volume: 'very good',
},
belt_loop: '3'
}
}
first_entries = expected.dup
first_entries.delete (Date.today - 1).to_s
sample_data = first_entries.merge({
"#{(Date.today - 4).to_s}" => {
sleep: '9.5',
exercise: 'great',
diet: {
quality: 'good',
volume: 'very good',
},
belt_loop: '3'
},
}).to_yaml
File.open('fixture.yml', 'w') { |f| f.write sample_data }
log = HealthLog.new 'fixture.yml'
assert_equal expected, log.last_n_days(3)
end
def sample_input
<<-TXT.gsub(/\s+/,' ').strip << ("\n")
w: 200.5 dq: ate cookie bl: 4 dv: ate too much s: not bad c: random comments x: strong workout
TXT
end
def expected_output
{
@date => {
weight: '200.5',
'diet quality': "ate cookie",
'belt loop': '4',
'diet volume': "ate too much",
sleep: "not bad",
comments: 'random comments',
exercise: "strong workout",
}
}
end
end