/
gas_test.go
84 lines (71 loc) · 2.65 KB
/
gas_test.go
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
package main
import "testing"
func TestAddGas(t *testing.T) {
mixture := GasMixture{}
mixture.Volume = 1000
mixture.AddGas(GAS_O2, 50)
//addition of new gas to mixture
if amount := mixture.GetMolarValue(GAS_O2); amount != 50 {
t.Errorf("Bad gas add. Added 50, got %f", amount)
}
if total := mixture.totalMolar; total != 50 {
t.Errorf("Bad gas add. Added 50 to total, got %f", total)
}
//addition of gas to mixture that already contains some of the gas
mixture.AddGas(GAS_O2, 100)
if amount := mixture.GetMolarValue(GAS_O2); amount != 150 {
t.Errorf("Bad gas add. Added 100 to 50, got %f", amount)
}
if total := mixture.totalMolar; total != 150 {
t.Errorf("Bad gas add. Added 100 to total, got %f (expected 150)", total)
}
//addition of second gas to mixture, ensure it doesn't mess up the first
mixture.AddGas(GAS_N2, 200)
if amount := mixture.GetMolarValue(GAS_N2); amount != 200 {
t.Errorf("Bad gas add. Added 200 N2, got N2 = %f", amount)
}
if amount := mixture.GetMolarValue(GAS_O2); amount != 150 {
t.Errorf("Bad gas add. Added 200 N2, got O2 = %f", amount)
}
if total := mixture.totalMolar; total != 350 {
t.Errorf("Bad gas add. Added 200 to total, got %f (expected 350)", total)
}
}
func TestRemoveGas(t *testing.T) {
mixture := GasMixture{}
mixture.Volume = 1000
mixture.AddGas(GAS_O2, 200)
//remove some gas
mixture.RemoveGas(GAS_O2, 100)
if amount := mixture.GetMolarValue(GAS_O2); amount != 100 {
t.Errorf("Bad gas remove. Removed 100 from 200, got %f", amount)
}
if total := mixture.totalMolar; total != 100 {
t.Errorf("Bad gas remove. Removed 100 from total, got %f (expected 100)", total)
}
//attempt to remove gas that isn't there
mixture.RemoveGas(GAS_N2, 100)
if amount := mixture.GetMolarValue(GAS_O2); amount != 100 {
t.Errorf("Bad gas remove. Removed N2 from O2 mixture, got O2 = %f", amount)
}
if total := mixture.totalMolar; total != 100 {
t.Errorf("Bad gas remove. Removed none from total, got %f (expected 100)", total)
}
//remove exact amount of gas remaining
mixture.RemoveGas(GAS_O2, 100)
if amount := mixture.GetMolarValue(GAS_O2); amount != 0 {
t.Errorf("Bad gas remove. Removed all O2, got O2 = %f", amount)
}
if total := mixture.totalMolar; total != 0 {
t.Errorf("Bad gas remove. Removed all from total, got %f (expected 0)", total)
}
mixture.AddGas(GAS_O2, 200)
//remove too much gas
mixture.RemoveGas(GAS_O2, 300)
if amount := mixture.GetMolarValue(GAS_O2); amount != 0 {
t.Errorf("Bad gas remove. Removed 300 O2, got O2 = %f (expected 0)", amount)
}
if total := mixture.totalMolar; total != 0 {
t.Errorf("Bad gas remove. Removed too much from total, got %f (expected 0)", total)
}
}