Skip to content

Commit

Permalink
Rename to 'xdice'
Browse files Browse the repository at this point in the history
  • Loading branch information
olinox14 committed Sep 21, 2017
1 parent 28e3674 commit 1af1b03
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 172 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**pydice**
**xdice**

*pydice* is a lightweight python library for managing dice, scores, and dice-notation patterns.
*xdice* is a lightweight python library for managing dice, scores, and dice-notation patterns.

It allows to easily interpret literal expressions as rolls of dice ('1d6', '3d4+3', '12d6+1d4'...etc.), then manipulate the results.

Expand All @@ -10,7 +10,7 @@ DiceRollParser has been tested with python 3.3+

### Documentation

See the **[full documentation](https://pydice.readthedocs.io/en/latest/)**
See the **[full documentation](https://xdice.readthedocs.io/en/latest/)**

#### Examples:

Expand Down Expand Up @@ -52,7 +52,7 @@ Run `python roll.py [options] <expr>`
-s Numeric score only

-h --help Displays help message
--version Displays current pydice version
--version Displays current xdice version


#### CONTRIBUTION
Expand All @@ -61,11 +61,11 @@ Any opinion / contribution is welcome, please contact us.

#### TO INSTALL

pip install pydice
pip install xdice

#### License

*pydice* is under GNU License
*xdice* is under GNU License

#### Author

Expand Down
Binary file removed dist/pydice-1.0.0.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion nose2.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ with-coverage = True

[coverage]
always-on = True
coverage = dice
coverage = xdice
coverage-report = html
99 changes: 0 additions & 99 deletions pydice.egg-info/PKG-INFO

This file was deleted.

9 changes: 0 additions & 9 deletions pydice.egg-info/SOURCES.txt

This file was deleted.

1 change: 0 additions & 1 deletion pydice.egg-info/dependency_links.txt

This file was deleted.

2 changes: 0 additions & 2 deletions pydice.egg-info/top_level.txt

This file was deleted.

12 changes: 6 additions & 6 deletions roll.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
-s Numeric score only
-h --help Displays help message
--version Displays current pydice version
--version Displays current xdice version
"""
import sys

import dice
import xdice

def print_ex(string, exit_code=0):
""" print and exit """
Expand All @@ -24,20 +24,20 @@ def print_ex(string, exit_code=0):
print_ex(__doc__)

if "-v" in args:
print_ex("pydice {}".format(dice.__VERSION__))
print_ex("xdice {}".format(xdice.__VERSION__))

score_only = False
if "-s" in args:
score_only = True
args.remove("-s")

if len(args) != 1:
print_ex("pydice CLI: invalid arguments\n" + __doc__, 1)
print_ex("xdice CLI: invalid arguments\n" + __doc__, 1)

pattern_string = args[0]

# Run pydice
ps = dice.roll(pattern_string)
# Run xdice
ps = xdice.roll(pattern_string)

if score_only:
print(ps)
Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
long_description = f.read()

setup(
name='pydice',
name='xdice',

version='1.0.0',

description='Lightweight python library for managing dice, scores, and dice-notation patterns.',
description='Lightweight python library for managing xdice, scores, and xdice-notation patterns.',
long_description=long_description,

url='https://github.com/cro-ki/pydice',
url='https://github.com/cro-ki/xdice',

author='Olivier Massot',
author_email='croki.contact@gmail.com',

license='GNU',

py_modules=['dice', 'roll'],
py_modules=['xdice', 'roll'],
python_requires='>=3.3',

include_package_data=True,
Expand All @@ -49,6 +49,6 @@
'Programming Language :: Python :: 3.6',
],

keywords='dice roll d20 game random parser dices role board',
keywords='xdice roll d20 game random parser dices role board',

)
84 changes: 42 additions & 42 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,54 @@
'''
import unittest

import dice
import xdice


class Test(unittest.TestCase):
"""unitests for DiceRollParser"""

def test_secured_eval(self):
# refused
self.assertRaises(TypeError, dice._secured_eval, "open('foo', 'r')")
self.assertRaises(TypeError, xdice._secured_eval, "open('foo', 'r')")
# accepted
dice._secured_eval("1 + max([1,2,3])")
dice._secured_eval("1 + min([1,2,3])")
xdice._secured_eval("1 + max([1,2,3])")
xdice._secured_eval("1 + min([1,2,3])")

def test_patterns_validation(self):
"""check the with behaviour with valid / invalid patterns"""
# check valid expressions
dice.roll("3")
dice.roll("0d6")
dice.roll("1d6")
dice.roll("1d66")
dice.roll("1d4+2")
dice.roll("1d4-2")
dice.roll("1d4 - 2 ")
dice.roll("6d102+123")
dice.roll("6d102+123+8d6")
dice.roll("6d102+123+8d6+2+1+1-8-6d4+8-2d101+100d2")
dice.roll("32+3-0-2")
dice.roll("1d1-3")
dice.roll("1000d1000")
dice.roll("10 d 10")
dice.roll("10*1d10/2")
dice.roll("1d20**2")
dice.roll("abs(1d6-1d10)")
dice.roll("max(1d6,2d4)")
dice.roll("min(1d6,2d4)")
xdice.roll("3")
xdice.roll("0d6")
xdice.roll("1d6")
xdice.roll("1d66")
xdice.roll("1d4+2")
xdice.roll("1d4-2")
xdice.roll("1d4 - 2 ")
xdice.roll("6d102+123")
xdice.roll("6d102+123+8d6")
xdice.roll("6d102+123+8d6+2+1+1-8-6d4+8-2d101+100d2")
xdice.roll("32+3-0-2")
xdice.roll("1d1-3")
xdice.roll("1000d1000")
xdice.roll("10 d 10")
xdice.roll("10*1d10/2")
xdice.roll("1d20**2")
xdice.roll("abs(1d6-1d10)")
xdice.roll("max(1d6,2d4)")
xdice.roll("min(1d6,2d4)")

# test invalid expressions
self.assertRaises(SyntaxError, dice.roll, "1d-8")
self.assertRaises(SyntaxError, dice.roll, "1d")
self.assertRaises(ValueError, dice.roll, "")
self.assertRaises(ValueError, dice.roll, "1d0")
self.assertRaises(TypeError, dice.roll, "d6")
self.assertRaises(TypeError, dice.roll, "abc")
self.assertRaises(TypeError, dice.roll, "1d2,3")
self.assertRaises(SyntaxError, xdice.roll, "1d-8")
self.assertRaises(SyntaxError, xdice.roll, "1d")
self.assertRaises(ValueError, xdice.roll, "")
self.assertRaises(ValueError, xdice.roll, "1d0")
self.assertRaises(TypeError, xdice.roll, "d6")
self.assertRaises(TypeError, xdice.roll, "abc")
self.assertRaises(TypeError, xdice.roll, "1d2,3")

def test_dice_object(self):

d = dice.Dice(6, 6)
d = xdice.Dice(6, 6)
self.assertEqual(d.sides, 6)
self.assertEqual(d.amount, 6)
self.assertEqual(d.__repr__(), "<Dice; sides=6; amount=6>")
Expand All @@ -64,13 +64,13 @@ def test_dice_object(self):
self.assertRaises(ValueError, setattr, d, "amount", "a")
self.assertRaises(ValueError, setattr, d, "amount", None)

self.assertEqual(dice.Dice(1, 6).roll(), 6)
self.assertEqual(xdice.Dice(1, 6).roll(), 6)

self.assertEqual(dice.Dice.parse("6d1").roll(), 6)
self.assertEqual(xdice.Dice.parse("6d1").roll(), 6)

def test_score_object(self):

s = dice.Score([1, 2, 3])
s = xdice.Score([1, 2, 3])

self.assertEqual(s, 6)
self.assertEqual(str(s), "6")
Expand All @@ -82,40 +82,40 @@ def test_score_object(self):

def test_pattern_object(self):

p = dice.Pattern("6d1+6")
p = xdice.Pattern("6d1+6")

self.assertEqual(p._normalize("1 D 6"), "1d6")

p.compile()
self.assertEqual(p.format_string, "{0}+6")
self.assertEqual(p.dices, [dice.Dice(1, 6)])
self.assertEqual(p.dices, [xdice.Dice(1, 6)])

self.assertEqual(p.roll(), 12)

def test_patternscore_objet(self):
ps = dice.PatternScore("{0}+6", [dice.Score([1, 1, 1, 1, 1, 1])])
ps = xdice.PatternScore("{0}+6", [xdice.Score([1, 1, 1, 1, 1, 1])])

self.assertEqual(ps, 12)
self.assertEqual(ps.score(0), 6)
self.assertEqual(ps.scores(), [6])
self.assertEqual(ps.format(), "[1, 1, 1, 1, 1, 1]+6")

def test_compile(self):
p1 = dice.compile("6d1+6")
p2 = dice.Pattern("6d1+6")
p1 = xdice.compile("6d1+6")
p2 = xdice.Pattern("6d1+6")
p2.compile()

self.assertEqual(p1.format_string, p2.format_string)
self.assertEqual(p1.dices, p2.dices)

def test_roll(self):
ps1 = dice.roll("6d1+6")
ps2 = dice.PatternScore("{0}+6", [dice.Score([1, 1, 1, 1, 1, 1])])
ps1 = xdice.roll("6d1+6")
ps2 = xdice.PatternScore("{0}+6", [xdice.Score([1, 1, 1, 1, 1, 1])])

self.assertEqual(ps1, ps2)

def test_rolldice(self):
self.assertEqual(dice.rolldice(1, 6), dice.Dice(1, 6).roll())
self.assertEqual(xdice.rolldice(1, 6), xdice.Dice(1, 6).roll())

if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion dice.py → xdice.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
pydice is a lightweight python 3.3+ library for managing rolls of dice.
xdice is a lightweight python 3.3+ library for managing rolls of dice.
License: GNU
Expand Down

0 comments on commit 1af1b03

Please sign in to comment.