]>
jfr.im git - irc/rizon/acid.git/blob - vizon/src/test/java/net/rizon/acid/plugins/vizon/BetValidatorTest.java
2 * Copyright (c) 2016, orillion <orillion@rizon.net>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
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.
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.
26 package net
.rizon
.acid
.plugins
.vizon
;
28 import java
.util
.Optional
;
29 import org
.junit
.Assert
;
30 import org
.junit
.Test
;
33 * Unit tests for the bet validator.
35 * @author orillion <orillion@rizon.net>
37 public class BetValidatorTest
40 * Test whether or not the validate method returns an empty optional when
41 * you present null to it.
44 public void validateNullTest()
48 Optional
<Bet
> result
= BetValidator
.validate(bet
);
50 Assert
.assertFalse(result
.isPresent());
54 * Test whether or not the validate method returns an empty optional when
55 * you present an empty to it.
58 public void validateEmptyStringTest()
62 Optional
<Bet
> result
= BetValidator
.validate(bet
);
64 Assert
.assertFalse(result
.isPresent());
68 * Test whether or not the validate method returns an empty optional when
69 * you present an incorrect string to it.
72 public void validateNotEnoughNumbersTest()
76 Optional
<Bet
> result
= BetValidator
.validate(bet
);
78 Assert
.assertFalse(result
.isPresent());
82 * Test whether or not the validate method returns an empty optional when
83 * you present an incorrect string to it.
86 public void validateTooManyNumbersTest()
88 String bet
= "1 2 3 4 5 6 7";
90 Optional
<Bet
> result
= BetValidator
.validate(bet
);
92 Assert
.assertFalse(result
.isPresent());
96 * Test whether or not the validate method returns an empty optional when
97 * you present an incorrect string to it.
100 public void validateDoubleNumbersTest()
102 String bet
= "1 2 1 3 4 5";
104 Optional
<Bet
> result
= BetValidator
.validate(bet
);
106 Assert
.assertFalse(result
.isPresent());
110 * Test whether or not the validate method returns an empty optional when
111 * you present an incorrect string to it.
114 public void validateNegativeNumbersTest()
116 String bet
= "1 2 -11 3 4 5";
118 Optional
<Bet
> result
= BetValidator
.validate(bet
);
120 Assert
.assertFalse(result
.isPresent());
124 * Test whether or not the validate method returns an empty optional when
125 * you present an incorrect string to it.
128 public void validateOutLowerBoundTest()
130 String bet
= "1 2 0 3 4 5";
132 Optional
<Bet
> result
= BetValidator
.validate(bet
);
134 Assert
.assertFalse(result
.isPresent());
138 * Test whether or not the validate method returns an empty optional when
139 * you present an incorrect string to it.
142 public void validateOutUpperBoundTest()
144 String bet
= "1 2 30 3 4 5";
146 Optional
<Bet
> result
= BetValidator
.validate(bet
);
148 Assert
.assertFalse(result
.isPresent());
152 * Test whether or not the validate method returns an filled optional when
153 * you present a correct string to it.
156 public void validateOnLowerBoundTest()
158 String bet
= "1 2 3 4 5 6";
160 Optional
<Bet
> result
= BetValidator
.validate(bet
);
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());
172 * Test whether or not the validate method returns an filled optional when
173 * you present a correct string to it.
176 public void validateOnUpperBoundTest()
178 String bet
= "1 2 3 4 5 29";
180 Optional
<Bet
> result
= BetValidator
.validate(bet
);
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());
192 * Test whether or not the validate method returns an filled optional when
193 * you present a correct string to it.
196 public void validateResultRemainsUnsortedTest()
198 String bet
= "9 2 11 4 21 29";
200 Optional
<Bet
> result
= BetValidator
.validate(bet
);
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());
212 * Test whether or not the validator does not mind multiple spaces in front.
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
219 public void validateAccidentalSpaceFrontTest()
221 String bet
= " 9 2 11 4 21 29";
223 Optional
<Bet
> result
= BetValidator
.validate(bet
);
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());
235 * Test whether or not the validator does not mind multiple spaces at the
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
243 public void validateAccidentalSpaceEndTest()
245 String bet
= "9 2 11 4 21 29 ";
247 Optional
<Bet
> result
= BetValidator
.validate(bet
);
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());
259 * Test whether or not the validator does not mind multiple spaces in
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
267 public void validateAccidentalSpaceBetweenTest()
269 String bet
= "9 2 11 4 21 29";
271 Optional
<Bet
> result
= BetValidator
.validate(bet
);
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());
283 * Test whether or not the validator returns an empty Optional when
284 * presented with gibberish.
287 public void validateNoNumbersTest()
289 String bet
= "hello world!";
291 Optional
<Bet
> result
= BetValidator
.validate(bet
);
293 Assert
.assertFalse(result
.isPresent());
297 * Test whether or not the validator returns an empty Optional when
298 * presented with gibberish.
301 public void validateTextAfterNumbersTest()
303 String bet
= "1 2 3 4 5 6 hello world!";
305 Optional
<Bet
> result
= BetValidator
.validate(bet
);
307 Assert
.assertFalse(result
.isPresent());