Skip to content

Commit 93b8d45

Browse files
committed
Reorganized tests
1 parent 5a513bf commit 93b8d45

13 files changed

Lines changed: 489 additions & 330 deletions

tests/parser/dice/__init__.py

Whitespace-only changes.

tests/parser/test_dice_parser_dice.py renamed to tests/parser/dice/test_dice_parser_dice.py

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import sys
44
import unittest
55

6-
from dice_notation.dice import Rollable
76
from dice_notation.parser import DiceParser
87

98
"""
@@ -87,81 +86,3 @@ def test_max(self):
8786

8887
self.assertEqual(sys.maxsize, dice.quantity)
8988
self.assertEqual(sys.maxsize, dice.sides)
90-
91-
92-
class TestDiceBinaryOperation(unittest.TestCase):
93-
"""
94-
Tests that the parser can work with pure numeric operations.
95-
"""
96-
97-
def setUp(self):
98-
"""
99-
Here the tests environment would be prepared.
100-
"""
101-
self.parser = DiceParser()
102-
103-
def test_add(self):
104-
"""
105-
Tests that numeric additions are done correctly.
106-
"""
107-
result = self.parser.parse("1d6+2d20")
108-
109-
dice_left = result.left
110-
dice_right = result.right
111-
112-
self.assertEqual(1, dice_left.quantity)
113-
self.assertEqual(6, dice_left.sides)
114-
115-
self.assertEqual(2, dice_right.quantity)
116-
self.assertEqual(20, dice_right.sides)
117-
118-
def test_sub(self):
119-
"""
120-
Tests that numeric subtractions are done correctly.
121-
"""
122-
result = self.parser.parse("3d12-1D6")
123-
124-
dice_left = result.left
125-
dice_right = result.right
126-
127-
self.assertEqual(3, dice_left.quantity)
128-
self.assertEqual(12, dice_left.sides)
129-
130-
self.assertEqual(1, dice_right.quantity)
131-
self.assertEqual(6, dice_right.sides)
132-
133-
134-
class TestRollable(unittest.TestCase):
135-
"""
136-
Tests that the parser can work with pure numeric operations.
137-
"""
138-
139-
def setUp(self):
140-
"""
141-
Here the tests environment would be prepared.
142-
"""
143-
self.parser = DiceParser()
144-
145-
def test_simpleDice_rollable(self):
146-
"""
147-
Tests that a simple dice notation can be parsed.
148-
"""
149-
dice = self.parser.parse("1d6")
150-
151-
self.assertTrue(isinstance(dice, Rollable))
152-
153-
def test_add_rollable(self):
154-
"""
155-
Tests that numeric additions are done correctly.
156-
"""
157-
result = self.parser.parse("1d6+2d20")
158-
159-
self.assertTrue(isinstance(result, Rollable))
160-
161-
def test_sub_rollable(self):
162-
"""
163-
Tests that numeric subtractions are done correctly.
164-
"""
165-
result = self.parser.parse("3d12-1D6")
166-
167-
self.assertTrue(isinstance(result, Rollable))
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import unittest
4+
5+
from dice_notation.parser import DiceParser
6+
7+
"""
8+
Dice parser tests for expressions only containing dice.
9+
"""
10+
11+
__author__ = 'Bernardo Martínez Garrido'
12+
__license__ = 'MIT'
13+
14+
15+
class TestDiceBinaryOperation(unittest.TestCase):
16+
"""
17+
Tests that the parser can work with pure numeric operations.
18+
"""
19+
20+
def setUp(self):
21+
"""
22+
Here the tests environment would be prepared.
23+
"""
24+
self.parser = DiceParser()
25+
26+
def test_add(self):
27+
"""
28+
Tests that numeric additions are done correctly.
29+
"""
30+
result = self.parser.parse("1d6+2d20")
31+
32+
dice_left = result.left
33+
dice_right = result.right
34+
35+
self.assertEqual(1, dice_left.quantity)
36+
self.assertEqual(6, dice_left.sides)
37+
38+
self.assertEqual(2, dice_right.quantity)
39+
self.assertEqual(20, dice_right.sides)
40+
41+
def test_sub(self):
42+
"""
43+
Tests that numeric subtractions are done correctly.
44+
"""
45+
result = self.parser.parse("3d12-1D6")
46+
47+
dice_left = result.left
48+
dice_right = result.right
49+
50+
self.assertEqual(3, dice_left.quantity)
51+
self.assertEqual(12, dice_left.sides)
52+
53+
self.assertEqual(1, dice_right.quantity)
54+
self.assertEqual(6, dice_right.sides)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import unittest
4+
5+
from dice_notation.dice import Rollable
6+
from dice_notation.parser import DiceParser
7+
8+
"""
9+
Dice parser tests for expressions only containing dice.
10+
"""
11+
12+
__author__ = 'Bernardo Martínez Garrido'
13+
__license__ = 'MIT'
14+
15+
16+
class TestRollable(unittest.TestCase):
17+
"""
18+
Tests that the parser can work with pure numeric operations.
19+
"""
20+
21+
def setUp(self):
22+
"""
23+
Here the tests environment would be prepared.
24+
"""
25+
self.parser = DiceParser()
26+
27+
def test_simpleDice_rollable(self):
28+
"""
29+
Tests that a simple dice notation can be parsed.
30+
"""
31+
dice = self.parser.parse("1d6")
32+
33+
self.assertTrue(isinstance(dice, Rollable))
34+
35+
def test_add_rollable(self):
36+
"""
37+
Tests that numeric additions are done correctly.
38+
"""
39+
result = self.parser.parse("1d6+2d20")
40+
41+
self.assertTrue(isinstance(result, Rollable))
42+
43+
def test_sub_rollable(self):
44+
"""
45+
Tests that numeric subtractions are done correctly.
46+
"""
47+
result = self.parser.parse("3d12-1D6")
48+
49+
self.assertTrue(isinstance(result, Rollable))

tests/parser/number/__init__.py

Whitespace-only changes.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import unittest
4+
5+
from dice_notation.parser import DiceParser
6+
7+
"""
8+
Dice parser tests for purely numeric expressions.
9+
"""
10+
11+
__author__ = 'Bernardo Martínez Garrido'
12+
__license__ = 'MIT'
13+
14+
15+
class TestNumber(unittest.TestCase):
16+
"""
17+
Tests that the parser can work with pure numeric operations.
18+
"""
19+
20+
def setUp(self):
21+
"""
22+
Here the tests environment would be prepared.
23+
"""
24+
self.parser = DiceParser()
25+
26+
def test_positive(self):
27+
"""
28+
Tests that numeric additions are done correctly.
29+
"""
30+
result = self.parser.parse("5")
31+
32+
self.assertEqual(5, result)
33+
34+
def test_zero(self):
35+
"""
36+
Tests that numeric additions are done correctly.
37+
"""
38+
result = self.parser.parse("0")
39+
40+
self.assertEqual(0, result)
41+
42+
def test_negative(self):
43+
"""
44+
Tests that numeric additions are done correctly.
45+
"""
46+
result = self.parser.parse("-5")
47+
48+
# TODO: currently not supported
49+
# self.assertEqual(-5, result)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import unittest
4+
5+
from dice_notation.parser import DiceParser
6+
7+
"""
8+
Dice parser tests for purely numeric expressions.
9+
"""
10+
11+
__author__ = 'Bernardo Martínez Garrido'
12+
__license__ = 'MIT'
13+
14+
15+
class TestAdd(unittest.TestCase):
16+
"""
17+
Tests that the parser can work with pure numeric operations.
18+
"""
19+
20+
def setUp(self):
21+
"""
22+
Here the tests environment would be prepared.
23+
"""
24+
self.parser = DiceParser()
25+
26+
def test_add(self):
27+
"""
28+
Tests that numeric additions are done correctly.
29+
"""
30+
result = self.parser.parse("1+2")
31+
32+
self.assertEqual(3, result)
33+
34+
def test_add_toNegative(self):
35+
"""
36+
Tests that numeric additions are done correctly.
37+
"""
38+
result = self.parser.parse("-1+2")
39+
40+
# TODO: currently not supported
41+
# self.assertEqual(1, result)
42+
43+
44+
class TestAddLong(unittest.TestCase):
45+
"""
46+
Tests that the parser can work with pure numeric operations.
47+
"""
48+
49+
def setUp(self):
50+
"""
51+
Here the tests environment would be prepared.
52+
"""
53+
self.parser = DiceParser()
54+
55+
def test_longAdd(self):
56+
"""
57+
Tests that numeric additions are done correctly.
58+
"""
59+
result = self.parser.parse("1+2+3")
60+
61+
self.assertEqual(6, result)
62+
63+
def test_longerAdd(self):
64+
"""
65+
Tests that numeric additions are done correctly.
66+
"""
67+
result = self.parser.parse("1+2+3+4+5")
68+
69+
self.assertEqual(15, result)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import unittest
4+
5+
from dice_notation.parser import DiceParser
6+
7+
"""
8+
Dice parser tests for purely numeric expressions.
9+
"""
10+
11+
__author__ = 'Bernardo Martínez Garrido'
12+
__license__ = 'MIT'
13+
14+
15+
class TestNumericBinaryOperationMixed(unittest.TestCase):
16+
"""
17+
Tests that the parser can work with pure numeric operations.
18+
"""
19+
20+
def setUp(self):
21+
"""
22+
Here the tests environment would be prepared.
23+
"""
24+
self.parser = DiceParser()
25+
26+
def test_addAndSub(self):
27+
"""
28+
Tests that numeric additions are done correctly.
29+
"""
30+
result = self.parser.parse("1+2-3")
31+
32+
self.assertEqual(0, result)
33+
34+
def test_subAndAdd(self):
35+
"""
36+
Tests that numeric subtractions are done correctly.
37+
"""
38+
result = self.parser.parse("3-1+2")
39+
40+
self.assertEqual(4, result)

0 commit comments

Comments
 (0)