예제 #1
0
    def test_Wheel(self):
        """
        http://www.itmaybeahack.com/book/oodesign-python-2.1/html/roulette/wheel.html#the-random-bin-selection-responsibility

        Wheel Deliverables
        A class which performs a unit test of building the Wheel class. The unit test should create
        several instances of Outcome, two instances of Bin, and an instance of Wheel. The unit test
        should establish that Bins can be added to the Wheel. A Non-Random Random Number Generator
        class, to be used for testing. A class which tests the Wheel and NonRandom class by
        selecting values from a Wheel object.
        """

        outcome_one = Outcome("Red", 1)
        outcome_two = Outcome("Corner", 2)
        outcome_three = Outcome("Black", 3)
        outcome_four = Outcome("Street", 4)

        nonrandom = NonRandom()
        nonrandom.set_seed(1)

        wheel_one = Wheel(nonrandom)
        wheel_one.add_outcome(1, outcome_one)
        wheel_one.add_outcome(2, outcome_two)
        wheel_one.next()

        self.assertTrue(wheel_one.next(), outcome_one )

        # test get_outcome
        self.wheel_two = Wheel(nonrandom)
        BB = BinBuilder()
        BB.build_bins(self.wheel_two)
예제 #2
0
    def test_Wheel(self):
        """
        http://www.itmaybeahack.com/book/oodesign-python-2.1/html/roulette/wheel.html#the-random-bin-selection-responsibility

        Wheel Deliverables
        A class which performs a unit test of building the Wheel class. The unit test should create
        several instances of Outcome, two instances of Bin, and an instance of Wheel. The unit test
        should establish that Bins can be added to the Wheel. A Non-Random Random Number Generator
        class, to be used for testing. A class which tests the Wheel and NonRandom class by
        selecting values from a Wheel object.
        """

        outcome_one = Outcome("Red", 1)
        outcome_two = Outcome("Corner", 2)
        outcome_three = Outcome("Black", 3)
        outcome_four = Outcome("Street", 4)

        nonrandom = NonRandom()
        nonrandom.set_seed(1)

        wheel_one = Wheel(nonrandom)
        wheel_one.add_outcome(1, outcome_one)
        wheel_one.add_outcome(2, outcome_two)
        wheel_one.next()

        self.assertTrue(wheel_one.next(), outcome_one)

        # test get_outcome
        self.wheel_two = Wheel(nonrandom)
        BB = BinBuilder()
        BB.build_bins(self.wheel_two)
예제 #3
0
class TestWheel:
    def setup_method(self):
        self.wheel = Wheel(1)

    def test_initialize(self):
        assert len(self.wheel.bins) == 38
        for b in self.wheel.bins:
            assert len(b) > 0
            assert len(b) < 20

    def test_add_bin(self):
        b1 = Bin([Outcome("0", 35)])
        self.wheel.add_bin(10, b1)
        assert self.wheel.get(10) == b1

    def test_next(self):
        r = random.Random()
        r.setstate(self.wheel.rng.getstate())

        b1 = Bin([Outcome("Red", 5)])
        b2 = Bin([Outcome("0", 35), Outcome("Black", 5)])

        self.wheel.add_bin(r.randint(0, 38), b1)
        self.wheel.add_bin(r.randint(0, 38), b2)

        assert self.wheel.next() == b1
        assert self.wheel.next() == b2
        assert self.wheel.next() != b2

    def test_add_outcome(self):
        o1 = Outcome("test", 35)

        self.wheel.add_outcome(4, o1)
        assert o1 in self.wheel.get(4)

    def test_get_bin(self):
        b1 = Bin([Outcome("Red", 5)])
        self.wheel.add_bin(3, b1)
        assert self.wheel.get(3) == b1

    def test_get_outcome(self):
        o1 = Outcome("0", 35)
        self.wheel.add_outcome(4, o1)

        assert self.wheel.get_outcome("0") == o1
        assert self.wheel.get_outcome("gibberish") == None

    def test_get_bin_iterator(self):
        iterator = self.wheel.get_all_bins()
        for i in range(37):
            bin_iter = next(iterator)
            assert isinstance(bin_iter, Bin) == True
            assert self.wheel.get_outcome(
                "{}".format(i)) in bin_iter.get_outcome_iterator()

        assert self.wheel.get_outcome("00") in next(iterator)
예제 #4
0
def test_add_outcome():
    wheel = Wheel()

    wheel.add_outcome(0, Outcome(f'0', 35))
    wheel.add_outcome(0, Outcome(f'0', 35))

    assert Outcome(f'0', 35) in wheel.get(0)
    assert 1 == len(wheel.get(0))

    wheel.add_outcome(0, Outcome(f'street', 11))
    assert Outcome(f'street', 11) in wheel.get(0)
    assert 2 == len(wheel.get(0))
def test_wheel_sequence():
    wheel = Wheel()
    wheel.add_outcome(8, {Outcome("test", 1)})
    wheel.randgenerator.seed(1)
    assert Outcome("test", 1) in wheel.choose()