-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.rs
230 lines (198 loc) · 6.61 KB
/
test.rs
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
use arithmetic_sign::prelude::*;
#[test]
fn f32()
{
use std::convert::TryFrom;
assert_eq!(Sign::try_from(std::f32::NAN), Err(ArithmeticSignError::Nan));
assert_eq!(Sign::try_from(std::f32::NEG_INFINITY), Ok(Sign::Negative));
assert_eq!(Sign::try_from(std::f32::INFINITY), Ok(Sign::Positive));
assert_eq!(Sign::try_from(std::f32::MIN), Ok(Sign::Negative));
assert_eq!(Sign::try_from(-1f32), Ok(Sign::Negative));
assert_eq!(Sign::try_from(0f32), Ok(Sign::Positive));
assert_eq!(Sign::try_from(1f32), Ok(Sign::Positive));
assert_eq!(Sign::try_from(std::f32::MAX), Ok(Sign::Positive));
assert_eq!(Sign::Positive.as_f32(), 1f32);
assert_eq!(Sign::Negative.as_f32(), -1f32);
}
#[test]
fn f64()
{
use std::convert::TryFrom;
assert_eq!(Sign::try_from(std::f64::NAN), Err(ArithmeticSignError::Nan));
assert_eq!(Sign::try_from(std::f64::NEG_INFINITY), Ok(Sign::Negative));
assert_eq!(Sign::try_from(std::f64::INFINITY), Ok(Sign::Positive));
assert_eq!(Sign::try_from(std::f64::MIN), Ok(Sign::Negative));
assert_eq!(Sign::try_from(-1f64), Ok(Sign::Negative));
assert_eq!(Sign::try_from(0f64), Ok(Sign::Positive));
assert_eq!(Sign::try_from(1f64), Ok(Sign::Positive));
assert_eq!(Sign::try_from(std::f64::MAX), Ok(Sign::Positive));
assert_eq!(Sign::Positive.as_f64(), 1f64);
assert_eq!(Sign::Negative.as_f64(), -1f64);
}
#[test]
fn i8()
{
assert_eq!(Sign::from(std::i8::MIN), Sign::Negative);
assert_eq!(Sign::from(-1i8), Sign::Negative);
assert_eq!(Sign::from(0i8), Sign::Positive);
assert_eq!(Sign::from(1i8), Sign::Positive);
assert_eq!(Sign::from(std::i8::MAX), Sign::Positive);
assert_eq!(Sign::Positive.as_i8(), 1i8);
assert_eq!(Sign::Negative.as_i8(), -1i8);
}
#[test]
fn i16()
{
assert_eq!(Sign::from(std::i16::MIN), Sign::Negative);
assert_eq!(Sign::from(-1i16), Sign::Negative);
assert_eq!(Sign::from(0i16), Sign::Positive);
assert_eq!(Sign::from(1i16), Sign::Positive);
assert_eq!(Sign::from(std::i16::MAX), Sign::Positive);
assert_eq!(Sign::Positive.as_i16(), 1i16);
assert_eq!(Sign::Negative.as_i16(), -1i16);
}
#[test]
fn i32()
{
assert_eq!(Sign::from(std::i32::MIN), Sign::Negative);
assert_eq!(Sign::from(-1i32), Sign::Negative);
assert_eq!(Sign::from(0i32), Sign::Positive);
assert_eq!(Sign::from(1i32), Sign::Positive);
assert_eq!(Sign::from(std::i32::MAX), Sign::Positive);
assert_eq!(Sign::Positive.as_i32(), 1i32);
assert_eq!(Sign::Negative.as_i32(), -1i32);
}
#[test]
fn i64()
{
assert_eq!(Sign::from(std::i64::MIN), Sign::Negative);
assert_eq!(Sign::from(-1i64), Sign::Negative);
assert_eq!(Sign::from(0i64), Sign::Positive);
assert_eq!(Sign::from(1i64), Sign::Positive);
assert_eq!(Sign::from(std::i64::MAX), Sign::Positive);
assert_eq!(Sign::Positive.as_i64(), 1i64);
assert_eq!(Sign::Negative.as_i64(), -1i64);
}
#[test]
fn i128()
{
assert_eq!(Sign::from(std::i128::MIN), Sign::Negative);
assert_eq!(Sign::from(-1i128), Sign::Negative);
assert_eq!(Sign::from(0i128), Sign::Positive);
assert_eq!(Sign::from(1i128), Sign::Positive);
assert_eq!(Sign::from(std::i128::MAX), Sign::Positive);
assert_eq!(Sign::Positive.as_i128(), 1i128);
assert_eq!(Sign::Negative.as_i128(), -1i128);
}
#[test]
fn u8()
{
assert_eq!(Sign::from(std::u8::MIN), Sign::Positive);
assert_eq!(Sign::from(std::u8::MAX), Sign::Positive);
assert_eq!(Sign::Positive.as_u8(), Ok(1u8));
assert_eq!(Sign::Negative.as_u8(), Err(ArithmeticSignError::Negative));
}
#[test]
fn u16()
{
assert_eq!(Sign::from(std::u16::MIN), Sign::Positive);
assert_eq!(Sign::from(std::u16::MAX), Sign::Positive);
assert_eq!(Sign::Positive.as_u16(), Ok(1u16));
assert_eq!(Sign::Negative.as_u16(), Err(ArithmeticSignError::Negative));
}
#[test]
fn u32()
{
assert_eq!(Sign::from(std::u32::MIN), Sign::Positive);
assert_eq!(Sign::from(std::u32::MAX), Sign::Positive);
assert_eq!(Sign::Positive.as_u32(), Ok(1u32));
assert_eq!(Sign::Negative.as_u32(), Err(ArithmeticSignError::Negative));
}
#[test]
fn u64()
{
assert_eq!(Sign::from(std::u64::MIN), Sign::Positive);
assert_eq!(Sign::from(std::u64::MAX), Sign::Positive);
assert_eq!(Sign::Positive.as_u64(), Ok(1u64));
assert_eq!(Sign::Negative.as_u64(), Err(ArithmeticSignError::Negative));
}
#[test]
fn u128()
{
assert_eq!(Sign::from(std::u128::MIN), Sign::Positive);
assert_eq!(Sign::from(std::u128::MAX), Sign::Positive);
assert_eq!(Sign::Positive.as_u128(), Ok(1u128));
assert_eq!(Sign::Negative.as_u128(), Err(ArithmeticSignError::Negative));
}
#[test]
fn to_string()
{
assert_eq!(Sign::Positive.to_string(), "+");
assert_eq!(Sign::Negative.to_string(), "-");
}
#[test]
fn to_string_specific()
{
assert_eq!(Sign::Negative.to_string_specific("S", "N"), "S");
assert_eq!(Sign::Positive.to_string_specific("S", "N"), "N");
}
#[test]
fn is()
{
assert_eq!(Sign::Negative.is_negative(), true);
assert_eq!(Sign::Negative.is_positive(), false);
assert_eq!(Sign::Positive.is_negative(), false);
assert_eq!(Sign::Positive.is_positive(), true);
}
#[test]
fn mul()
{
assert_eq!(Sign::Positive * Sign::Positive, Sign::Positive);
assert_eq!(Sign::Positive * Sign::Negative, Sign::Negative);
assert_eq!(Sign::Negative * Sign::Positive, Sign::Negative);
assert_eq!(Sign::Negative * Sign::Negative, Sign::Positive);
}
#[test]
fn neg()
{
assert_eq!(-Sign::Positive, Sign::Negative);
assert_eq!(-Sign::Negative, Sign::Positive);
}
#[test]
fn not()
{
assert_eq!(!Sign::Positive, Sign::Negative);
assert_eq!(!Sign::Negative, Sign::Positive);
}
#[test]
fn eq()
{
assert_eq!(Sign::Positive == Sign::Positive, true);
assert_eq!(Sign::Positive != Sign::Positive, false);
assert_eq!(Sign::Negative == Sign::Negative, true);
assert_eq!(Sign::Negative != Sign::Negative, false);
assert_eq!(Sign::Negative == Sign::Positive, false);
assert_eq!(Sign::Negative != Sign::Positive, true);
assert_eq!(Sign::Positive == Sign::Negative, false);
assert_eq!(Sign::Positive != Sign::Negative, true);
}
#[test]
fn ord()
{
assert_eq!(Sign::Positive < Sign::Positive, false);
assert_eq!(Sign::Positive <= Sign::Positive, true);
assert_eq!(Sign::Positive > Sign::Positive, false);
assert_eq!(Sign::Positive >= Sign::Positive, true);
assert_eq!(Sign::Negative < Sign::Negative, false);
assert_eq!(Sign::Negative <= Sign::Negative, true);
assert_eq!(Sign::Negative > Sign::Negative, false);
assert_eq!(Sign::Negative >= Sign::Negative, true);
assert_eq!(Sign::Negative < Sign::Positive, true);
assert_eq!(Sign::Negative <= Sign::Positive, true);
assert_eq!(Sign::Negative > Sign::Positive, false);
assert_eq!(Sign::Negative >= Sign::Positive, false);
assert_eq!(Sign::Positive < Sign::Negative, false);
assert_eq!(Sign::Positive <= Sign::Negative, false);
assert_eq!(Sign::Positive > Sign::Negative, true);
assert_eq!(Sign::Positive >= Sign::Negative, true);
}