-
Notifications
You must be signed in to change notification settings - Fork 16
/
account_test.go
164 lines (121 loc) · 2.91 KB
/
account_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
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
157
158
159
160
161
162
163
164
package transaction
// Core
// Account test
// Copyright © 2017-2018 Eduard Sesigin. All rights reserved. Contacts: <claygod@yandex.ru>
import (
"testing"
)
func TestAccountAdd(t *testing.T) {
a := newAccount(100)
if a.addition(50) != 150 {
t.Error("Error addition (The sum does not match)")
}
if a.addition(-200) != -50 {
t.Error("Error adding (Negative balance)")
}
trialLimit = trialStop
if a.addition(-200) != permitError {
t.Error("Error adding")
}
trialLimit = trialLimitConst
}
func TestAccountAddingOverflow1(t *testing.T) {
a := newAccount(-1)
if res := a.addition(-0x8000000000000000); res != -0x8000000000000000 {
t.Error("Overflow error (1)")
t.Error(res)
}
}
func TestAccountAddingOverflow2(t *testing.T) {
a := newAccount(-0x8000000000000000)
if res := a.addition(-5); res != -5 {
t.Error("Overflow error (2)")
t.Error(res)
}
}
func TestAccountCredit(t *testing.T) {
a := newAccount(100)
if a.addition(-50) != 50 {
t.Error("Account incorrectly performed a credit operation")
}
if a.addition(-51) >= 0 {
t.Error("There must be a negative result")
}
if a.addition(-1) < 0 {
t.Error("A positive result was expected")
}
if b := a.addition(-1); b != 48 {
t.Error("Awaiting 48 and received:", b)
}
}
func TestAccountDebit(t *testing.T) {
a := newAccount(100)
if a.addition(50) != 150 {
t.Error("Account incorrectly performed a debit operation")
}
}
func TestAccountTotal(t *testing.T) {
a := newAccount(100)
a.addition(-1)
a.addition(1)
if a.total() != 100 {
t.Error("Balance error", a.total())
}
}
func TestAccountCath(t *testing.T) {
a := newAccount(100)
if !a.catch() {
t.Error("Account is free, but it was not possible to catch it")
}
if a.catch(); a.counter != 2 {
t.Error("Account counter error")
}
a.counter = -1
if a.catch() {
t.Error("There must be an answer `false`")
}
a.counter = 1
if !a.catch() {
t.Error("There must be an answer `true`")
}
}
func TestAccountThrow(t *testing.T) {
a := newAccount(100)
a.catch()
if a.throw(); a.counter != 0 {
t.Error("Failed to decrement the counter")
}
}
func TestAccountStart(t *testing.T) {
a := newAccount(100)
trialLimit = 200
a.counter = -1
if a.start() {
t.Error("Could not launch this account")
}
a.counter = 1
if !a.start() {
t.Error("The account already has a positive counter and the function should return the `true`")
}
a.counter = 0
if !a.start() {
t.Error("The account is already running and the function should return the` true`")
}
a.counter = permitError
if !a.start() {
t.Error("Account counter is in a position that allows launch. The launch is not carried out erroneously.")
}
trialLimit = trialLimitConst
}
func TestAccountStop(t *testing.T) {
a := newAccount(100)
trialLimit = 200
if !a.stop() {
t.Error("Could not stop this account")
}
a.counter = 1
if a.stop() {
t.Error("Could not stop this account22")
}
trialLimit = trialLimitConst
}