Ejemplo n.º 1
0
    def test_invalid(self):
        unused = set(string.ascii_lowercase) - set(RandomElement.DICE_MAP)

        bad_params = [(1, 0, "d"), (1, 6, "dd")]

        if unused:
            unused_char = random.choice(list(unused))
            bad_params.append((1, 6, unused_char))

        for params in bad_params:
            with raises(ValueError):
                utilities.dice_switch(*params)
Ejemplo n.º 2
0
    def test_invalid(self):
        unused = set(string.ascii_lowercase) - set(RandomElement.DICE_MAP)

        bad_params = [
            (1, 0, 'd'),
            (1, 6, 'dd')
        ]

        if unused:
            unused_char = random.choice(list(unused))
            bad_params.append((1, 6, unused_char))

        for params in bad_params:
            with raises(ValueError):
                utilities.dice_switch(*params)
Ejemplo n.º 3
0
 def from_string(cls, string):
     string = string.lower()
     for k in cls.DICE_MAP:
         ss = string.split(k)
         if len(ss) != 2:
             continue
         ss = [int(x) if x.isdigit() else x for x in ss]
         return dice_switch(ss[0], ss[1], k)
Ejemplo n.º 4
0
 def from_string(cls, string):
     string = string.lower()
     for k in cls.DICE_MAP:
         ss = string.split(k)
         if len(ss) != 2:
             continue
         ss = [int(x) if x.isdigit() else x for x in ss]
         return dice_switch(ss[0], ss[1], k)
Ejemplo n.º 5
0
    def parse(cls, string, location, tokens):
        if len(tokens) > 3:
            msg = ('Cannot stack dice operators! Try disabiguating your '
                   'expression with parentheses,')
            raise ParseFatalException(string, tokens[3].location, msg)

        amount, kind, dicetype = tokens
        try:
            ret = dice_switch(amount, dicetype, kind)
            return ret.set_parse_attributes(string, location, tokens)
        except ValueError as e:
            if len(e.args) > 1:
                if type(e.args[1]) is int:
                    location = tokens[e.args[1]].location
                # unused as of yet
                # elif isinstance(e.args[1], Element):
                #     location = e.args[1].location
            raise ParseFatalException(string, location, e.args[0])
Ejemplo n.º 6
0
    def parse(cls, string, location, tokens):
        if len(tokens) > 3:
            msg = ('Cannot stack dice operators! Try disabiguating your '
                   'expression with parentheses,')
            raise ParseFatalException(string, tokens[3].location, msg)

        amount, kind, dicetype = tokens
        try:
            ret = dice_switch(amount, dicetype, kind)
            return ret.set_parse_attributes(string, location, tokens)
        except ValueError as e:
            if len(e.args) > 1:
                if type(e.args[1]) is int:
                    location = tokens[e.args[1]].location
                # unused as of yet
                # elif isinstance(e.args[1], Element):
                #     location = e.args[1].location
            raise ParseFatalException(string, location, e.args[0])
Ejemplo n.º 7
0
    def test_fudge(self):
        assert type(utilities.dice_switch(1, 'f', 'd')) == FudgeDice
        assert type(utilities.dice_switch(1, 'f', 'u')) == FudgeDice

        with raises(ValueError):
            utilities.dice_switch(1, 'f', 'w')
Ejemplo n.º 8
0
 def test_percentile(self):
     for sep, cls in RandomElement.DICE_MAP.items():
         d = utilities.dice_switch(6, '%', sep)
         assert d.sides == 100
Ejemplo n.º 9
0
 def test_seperator_map(self):
     for sep, cls in RandomElement.DICE_MAP.items():
         d = utilities.dice_switch(6, 6, sep)
         assert type(d) is cls
Ejemplo n.º 10
0
    def test_fudge(self):
        assert type(utilities.dice_switch(1, "f", "d")) == FudgeDice
        assert type(utilities.dice_switch(1, "f", "u")) == FudgeDice

        with raises(ValueError):
            utilities.dice_switch(1, "f", "w")
Ejemplo n.º 11
0
 def test_percentile(self):
     for sep, cls in RandomElement.DICE_MAP.items():
         d = utilities.dice_switch(6, "%", sep)
         assert d.sides == 100
Ejemplo n.º 12
0
 def test_separator_map(self):
     for sep, cls in RandomElement.DICE_MAP.items():
         d = utilities.dice_switch(6, 6, sep)
         assert type(d) is cls
Ejemplo n.º 13
0
    def test_fudge(self):
        assert type(utilities.dice_switch(1, 'f', 'd')) == FudgeDice
        assert type(utilities.dice_switch(1, 'f', 'u')) == FudgeDice

        with raises(ValueError):
            utilities.dice_switch(1, 'f', 'w')