]> jfr.im git - irc/rizon/acid.git/blob - vizon/src/test/java/net/rizon/acid/plugins/vizon/BetValidatorTest.java
Merge branch 'vizon' into 'master'
[irc/rizon/acid.git] / vizon / src / test / java / net / rizon / acid / plugins / vizon / BetValidatorTest.java
1 /*
2 * Copyright (c) 2016, orillion <orillion@rizon.net>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
25 */
26 package net.rizon.acid.plugins.vizon;
27
28 import java.util.Optional;
29 import org.junit.Assert;
30 import org.junit.Test;
31
32 /**
33 * Unit tests for the bet validator.
34 *
35 * @author orillion <orillion@rizon.net>
36 */
37 public class BetValidatorTest
38 {
39 /**
40 * Test whether or not the validate method returns an empty optional when
41 * you present null to it.
42 */
43 @Test
44 public void validateNullTest()
45 {
46 String bet = null;
47
48 Optional<Bet> result = BetValidator.validate(bet);
49
50 Assert.assertFalse(result.isPresent());
51 }
52
53 /**
54 * Test whether or not the validate method returns an empty optional when
55 * you present an empty to it.
56 */
57 @Test
58 public void validateEmptyStringTest()
59 {
60 String bet = "";
61
62 Optional<Bet> result = BetValidator.validate(bet);
63
64 Assert.assertFalse(result.isPresent());
65 }
66
67 /**
68 * Test whether or not the validate method returns an empty optional when
69 * you present an incorrect string to it.
70 */
71 @Test
72 public void validateNotEnoughNumbersTest()
73 {
74 String bet = "1 2 3";
75
76 Optional<Bet> result = BetValidator.validate(bet);
77
78 Assert.assertFalse(result.isPresent());
79 }
80
81 /**
82 * Test whether or not the validate method returns an empty optional when
83 * you present an incorrect string to it.
84 */
85 @Test
86 public void validateTooManyNumbersTest()
87 {
88 String bet = "1 2 3 4 5 6 7";
89
90 Optional<Bet> result = BetValidator.validate(bet);
91
92 Assert.assertFalse(result.isPresent());
93 }
94
95 /**
96 * Test whether or not the validate method returns an empty optional when
97 * you present an incorrect string to it.
98 */
99 @Test
100 public void validateDoubleNumbersTest()
101 {
102 String bet = "1 2 1 3 4 5";
103
104 Optional<Bet> result = BetValidator.validate(bet);
105
106 Assert.assertFalse(result.isPresent());
107 }
108
109 /**
110 * Test whether or not the validate method returns an empty optional when
111 * you present an incorrect string to it.
112 */
113 @Test
114 public void validateNegativeNumbersTest()
115 {
116 String bet = "1 2 -11 3 4 5";
117
118 Optional<Bet> result = BetValidator.validate(bet);
119
120 Assert.assertFalse(result.isPresent());
121 }
122
123 /**
124 * Test whether or not the validate method returns an empty optional when
125 * you present an incorrect string to it.
126 */
127 @Test
128 public void validateOutLowerBoundTest()
129 {
130 String bet = "1 2 0 3 4 5";
131
132 Optional<Bet> result = BetValidator.validate(bet);
133
134 Assert.assertFalse(result.isPresent());
135 }
136
137 /**
138 * Test whether or not the validate method returns an empty optional when
139 * you present an incorrect string to it.
140 */
141 @Test
142 public void validateOutUpperBoundTest()
143 {
144 String bet = "1 2 30 3 4 5";
145
146 Optional<Bet> result = BetValidator.validate(bet);
147
148 Assert.assertFalse(result.isPresent());
149 }
150
151 /**
152 * Test whether or not the validate method returns an filled optional when
153 * you present a correct string to it.
154 */
155 @Test
156 public void validateOnLowerBoundTest()
157 {
158 String bet = "1 2 3 4 5 6";
159
160 Optional<Bet> result = BetValidator.validate(bet);
161
162 Assert.assertTrue(result.isPresent());
163 Assert.assertEquals(1, result.get().getFirst());
164 Assert.assertEquals(2, result.get().getSecond());
165 Assert.assertEquals(3, result.get().getThird());
166 Assert.assertEquals(4, result.get().getFourth());
167 Assert.assertEquals(5, result.get().getFifth());
168 Assert.assertEquals(6, result.get().getSixth());
169 }
170
171 /**
172 * Test whether or not the validate method returns an filled optional when
173 * you present a correct string to it.
174 */
175 @Test
176 public void validateOnUpperBoundTest()
177 {
178 String bet = "1 2 3 4 5 29";
179
180 Optional<Bet> result = BetValidator.validate(bet);
181
182 Assert.assertTrue(result.isPresent());
183 Assert.assertEquals(1, result.get().getFirst());
184 Assert.assertEquals(2, result.get().getSecond());
185 Assert.assertEquals(3, result.get().getThird());
186 Assert.assertEquals(4, result.get().getFourth());
187 Assert.assertEquals(5, result.get().getFifth());
188 Assert.assertEquals(29, result.get().getSixth());
189 }
190
191 /**
192 * Test whether or not the validate method returns an filled optional when
193 * you present a correct string to it.
194 */
195 @Test
196 public void validateResultRemainsUnsortedTest()
197 {
198 String bet = "9 2 11 4 21 29";
199
200 Optional<Bet> result = BetValidator.validate(bet);
201
202 Assert.assertTrue(result.isPresent());
203 Assert.assertEquals(9, result.get().getFirst());
204 Assert.assertEquals(2, result.get().getSecond());
205 Assert.assertEquals(11, result.get().getThird());
206 Assert.assertEquals(4, result.get().getFourth());
207 Assert.assertEquals(21, result.get().getFifth());
208 Assert.assertEquals(29, result.get().getSixth());
209 }
210
211 /**
212 * Test whether or not the validator does not mind multiple spaces in front.
213 * <p>
214 * Reasoning: Users can accidentally type a space and it's something that
215 * can be solved easy with a removeEmptyEntries call in standard java
216 * library.
217 */
218 @Test
219 public void validateAccidentalSpaceFrontTest()
220 {
221 String bet = " 9 2 11 4 21 29";
222
223 Optional<Bet> result = BetValidator.validate(bet);
224
225 Assert.assertTrue(result.isPresent());
226 Assert.assertEquals(9, result.get().getFirst());
227 Assert.assertEquals(2, result.get().getSecond());
228 Assert.assertEquals(11, result.get().getThird());
229 Assert.assertEquals(4, result.get().getFourth());
230 Assert.assertEquals(21, result.get().getFifth());
231 Assert.assertEquals(29, result.get().getSixth());
232 }
233
234 /**
235 * Test whether or not the validator does not mind multiple spaces at the
236 * end.
237 * <p>
238 * Reasoning: Users can accidentally type a space and it's something that
239 * can be solved easy with a removeEmptyEntries call in standard java
240 * library.
241 */
242 @Test
243 public void validateAccidentalSpaceEndTest()
244 {
245 String bet = "9 2 11 4 21 29 ";
246
247 Optional<Bet> result = BetValidator.validate(bet);
248
249 Assert.assertTrue(result.isPresent());
250 Assert.assertEquals(9, result.get().getFirst());
251 Assert.assertEquals(2, result.get().getSecond());
252 Assert.assertEquals(11, result.get().getThird());
253 Assert.assertEquals(4, result.get().getFourth());
254 Assert.assertEquals(21, result.get().getFifth());
255 Assert.assertEquals(29, result.get().getSixth());
256 }
257
258 /**
259 * Test whether or not the validator does not mind multiple spaces in
260 * between.
261 * <p>
262 * Reasoning: Users can accidentally type a space and it's something that
263 * can be solved easy with a removeEmptyEntries call in standard java
264 * library.
265 */
266 @Test
267 public void validateAccidentalSpaceBetweenTest()
268 {
269 String bet = "9 2 11 4 21 29";
270
271 Optional<Bet> result = BetValidator.validate(bet);
272
273 Assert.assertTrue(result.isPresent());
274 Assert.assertEquals(9, result.get().getFirst());
275 Assert.assertEquals(2, result.get().getSecond());
276 Assert.assertEquals(11, result.get().getThird());
277 Assert.assertEquals(4, result.get().getFourth());
278 Assert.assertEquals(21, result.get().getFifth());
279 Assert.assertEquals(29, result.get().getSixth());
280 }
281
282 /**
283 * Test whether or not the validator returns an empty Optional when
284 * presented with gibberish.
285 */
286 @Test
287 public void validateNoNumbersTest()
288 {
289 String bet = "hello world!";
290
291 Optional<Bet> result = BetValidator.validate(bet);
292
293 Assert.assertFalse(result.isPresent());
294 }
295
296 /**
297 * Test whether or not the validator returns an empty Optional when
298 * presented with gibberish.
299 */
300 @Test
301 public void validateTextAfterNumbersTest()
302 {
303 String bet = "1 2 3 4 5 6 hello world!";
304
305 Optional<Bet> result = BetValidator.validate(bet);
306
307 Assert.assertFalse(result.isPresent());
308 }
309 }