Exemplo n.º 1
0
    def test_100_repetitions(self):
        songs = ["1", "2", "3", "4", "5"]
        o = oracles.RepeatingOracle(songs)

        # Collect builds a list of 100, so we'll get "songs" 20 times over.
        collected = collect(o)

        self.assertListEqual(collected, songs * 20)
        self.assertEqual(collected[-1], o.current_song())
        self.assertIsNotNone(o.next_song())
Exemplo n.º 2
0
    def test_two_oracles(self):
        songs = ["1", "2", "3", "4", "5", "6"]

        p1 = oracles.PlaylistOracle(songs[:2])
        p2 = oracles.PlaylistOracle(songs[2:])

        o = oracles.ChainOracle()
        o.add(p1)
        o.add(p2)

        self.assertListEqual(collect(o), songs)
Exemplo n.º 3
0
    def test_add_empties(self):
        songs = ["1", "2", "3"]
        o = oracles.ChainOracle()
        o.add(None)
        memoized_none_song = o.current_song()
        o.add(oracles.PlaylistOracle([]))
        o.add(oracles.PlaylistOracle(songs))

        self.assertIsNone(memoized_none_song)
        self.assertIsNone(o.current_song())
        # Chop off the "None" from the start because of the first "current_song" call.
        self.assertListEqual(collect(o)[1:], songs)
Exemplo n.º 4
0
    def test_interrupt_before_finish(self):
        songs1 = ["1", "2", "3"]
        p1 = oracles.PlaylistOracle(songs1)
        songs2 = ["4", "5", "6"]
        p2 = oracles.PlaylistOracle(songs2)
        o = oracles.InterruptOracle(p1)

        collected = [o.current_song(), o.next_song()]
        o.interrupt(p2)
        collected.extend(collect(o))

        self.assertListEqual(collected, ["1", "2", "2", "4", "5", "6", "3"])
Exemplo n.º 5
0
    def test_memoizing_null(self):
        songs1 = ["1"]
        p1 = oracles.PlaylistOracle(songs1)
        o = oracles.SwitchOracle()

        o.set_oracle(None)
        none_song = o.current_song()
        o.set_oracle(p1)
        songs_collected = collect(o)

        self.assertIsNone(none_song)
        self.assertListEqual(songs_collected, [None, "1"])
Exemplo n.º 6
0
    def test_add_oracle(self):
        songs = ["1", "2", "3"]
        o = oracles.SwitchOracle()
        p1 = oracles.PlaylistOracle(songs)

        no_song_available_rv = o.current_song()
        o.set_oracle(p1)

        self.assertIsNone(no_song_available_rv)
        # Collect will return "None" first because we've memoized
        # "None" above, and collect calls "current_song()" first.
        self.assertListEqual(collect(o), [None, *songs])
Exemplo n.º 7
0
    def test_no_default(self):
        songs = ["1", "2", "3"]
        p1 = oracles.PlaylistOracle(songs)
        o = oracles.InterruptOracle(None)

        collected = [o.current_song()]
        o.interrupt(p1)
        collected.extend(collect(o))

        # Two "None"s, one from the initial "current_song", one from the "current_song" in collect()
        expected = list([None, None])
        expected.extend(songs)
        self.assertListEqual(collected, expected)
Exemplo n.º 8
0
    def test_add_halfway_through(self):
        songs1 = ["1", "2", "3", "4"]
        p1 = oracles.PlaylistOracle(songs1)
        songs2 = ["5", "6", "7"]
        p2 = oracles.PlaylistOracle(songs2)
        o = oracles.ChainOracle()

        o.add(p1)
        collected = [o.current_song(), o.next_song()]
        o.add(p2)

        # Shave the first entry off "collect" since we already got it.
        collected.extend(collect(o)[1:])

        self.assertListEqual(collected, songs1 + songs2)
Exemplo n.º 9
0
    def test_empty_start(self):
        songs = ["1", "2", "3"]
        p1 = oracles.PlaylistOracle(songs)
        p2 = oracles.PlaylistOracle(songs)

        o = oracles.ChainOracle()
        song0 = o.current_song()
        song1 = o.next_song()
        o.add(p1)
        o.add(p2)
        collected = collect(o)

        self.assertIsNone(song0)
        self.assertIsNone(song1)
        # Chop off the memoized "None" at the beginning.
        self.assertListEqual(collected[1:], songs * 2)
Exemplo n.º 10
0
    def test_none_after_finishing_chain_sticks(self):
        songs = ["1", "2", "3"]
        p1 = oracles.PlaylistOracle(songs)
        p2 = oracles.PlaylistOracle(songs)
        o = oracles.ChainOracle()

        o.add(p1)
        collected = collect(o)

        no_songs_available_rv = o.next_song()
        o.add(p2)
        memoized_to_none_rv = o.current_song()
        start_next_list_rv = o.next_song()

        self.assertEqual(collected, songs)
        self.assertIsNone(no_songs_available_rv)
        self.assertIsNone(memoized_to_none_rv)
        self.assertEqual(start_next_list_rv, "1")
Exemplo n.º 11
0
    def test_formerly_empty_oracle_not_ignored_when_filled_before_memoization(
            self):
        """This tests what happens when you fill an oracle that used to return null before
        accessing it for the first time (in this case, so - which unlike the test above, gets
        filled with songs before we call co.current_song() in collect())"""
        songs1 = ["1", "2", "3"]
        co = oracles.ChainOracle()
        co.add(oracles.PlaylistOracle([]))
        co.add(oracles.PlaylistOracle([]))
        so = oracles.SwitchOracle()
        co.add(so)
        co.add(oracles.PlaylistOracle(songs1))
        songs2 = ["4", "5", "6"]
        so.set_oracle(oracles.PlaylistOracle(songs2))

        collected = collect(co)

        self.assertListEqual(collected, ["4", "5", "6", "1", "2", "3"])
Exemplo n.º 12
0
    def test_zero_repeats(self):
        songs = ["1", "2", "3"]
        o = oracles.RepeatingOracle(songs, 0)
        collected = collect(o)

        self.assertListEqual(collected, [None])
Exemplo n.º 13
0
    def test_empty_playlist(self):
        ro = oracles.RepeatingOracle([], 10)

        self.assertListEqual(collect(ro), [None])
Exemplo n.º 14
0
    def test_default_behavior(self):
        songs = ["1", "2", "3"]
        p1 = oracles.PlaylistOracle(songs)
        o = oracles.InterruptOracle(p1)

        self.assertListEqual(collect(o), songs)
Exemplo n.º 15
0
 def test_basic_functionality(self):
     songs = ["1", "2", "3"]
     o = oracles.PlaylistOracle(songs)
     self.assertListEqual(collect(o), songs)
     self.assertIsNone(o.next_song())