コード例 #1
0
from splaytree import SplayTree
from utils.students import Stream, Student
from utils import fetch_stream_students

if __name__ == '__main__':
    stream_key = Stream('Інженерія програмного забезпечення', 2)

    students = fetch_stream_students(stream_key)
    student_tree = SplayTree([(student, None) for student in students])

    excellent_key = Student('Я', 'Я', 'Я', 90)

    exc_students = student_tree.split(excellent_key)

    for student, _ in exc_students:
        print(student)
コード例 #2
0
ファイル: test_splaytree.py プロジェクト: bertliang/first_one
 def setUp(self):
     ''' Setup test case each time. 
     '''
     self.test1 = SplayTree([5])
コード例 #3
0
ファイル: test_splaytree.py プロジェクト: bertliang/first_one
 def setUp(self):
     ''' Setup test case each time. 
     '''
     self.test1 = SplayTree([-2, -7, 15, 7, 12, 9, 5])
コード例 #4
0
ファイル: test_splaytree.py プロジェクト: bertliang/first_one
 def setUp(self):
     ''' Setup test case each time. 
     '''
     self.test1 = SplayTree(['c', 'z', 'b', 'a', 'd', 's'])
コード例 #5
0
    def test(self):
        value = 5
        t = SplayTree()
        # test empty
        assert t.isEmpty()
        # we cannot splay if tree is empty
        assert t.splay(None) is None
        # we cannot find anything in empty tree
        assert t.find(1) is None
        assert t.findMin() is None
        assert t.findMax() is None
        # cannot remove from empty
        assert t.remove(123) is None

        # insert into empty tree
        t.insert(value)
        assert not t.isEmpty()

        # insert into non-empty tree same value
        t.insert(value)
        assert not t.isEmpty()

        # insert different values
        t = SplayTree()
        t.insert(3)
        t.insert(5)
        t.insert(1)

        assert t.findMin() == 1
        assert t.findMax() == 5
        assert t.find(3) == 3
        assert t.find(10) is None

        t = SplayTree()
        t.insert(5)
        t.insert(3)
        t.insert(1)
        assert t.find(3) == 3
        assert t.findMin() == 1

        # test remove
        t = SplayTree()
        t.insert(5)
        t.insert(3)
        t.insert(1)
        t.remove(5)
        t.remove(3)
        t.remove(1)
        assert t.isEmpty()

        # test Node.equals()
        n1 = Node(3)
        n2 = Node(2 + 1)
        n3 = Node(1)
        assert n1.equals(n2)
        assert not n1.equals(n3)

        t = SplayTree()
        t.insert(7)
        t.insert(3)
        t.insert(7)
        assert t.find(7) == 7

        # lets do som RANGE testing !
        max = 1000
        min = 100
        t = SplayTree()
        t.insert(min)
        t.insert(max)

        for i in range(101, 999, 10):
            t.insert(i)
            assert t.find(i) == i
            assert t.findMin() == min
            assert t.findMax() == max