예제 #1
0
 def test_range_constructor(self):
     bst = pyset(10)
     self.assertEqual(bst.to_list(), list(range(10)))
     al = pyset(2, 10)
     self.assertEqual(al.to_list(), list(range(2, 10)))
     ls = pyset(10, 4, -1)
     self.assertEqual(ls.to_list(), list(sorted(range(10, 4, -1))))
예제 #2
0
 def test_several_instances(self):
     try:
         bst = pyset()
         nw = pyset()
         ny = pyset()
         bst.add(4)
         nw.add(6.84)
         ny.add("Hello world")
     except:
         self.fail()
예제 #3
0
 def test_from_list(self):
     bst = pyset()
     ex = list(range(200))
     lo = list(range(400, 50000))
     ex.extend(lo)
     bst.from_list(ex, lo)
     self.assertEqual(bst.to_list(), ex)
예제 #4
0
 def test_delete(self):
     bst = pyset()
     try:
         del bst
         with self.assertRaises(UnboundLocalError):
             bst.add("Hello world")
     except:
         self.fail()
예제 #5
0
    def test_iterations(self):
        expected = []
        bst = pyset()
        for i in range(1, 100):
            bst.add(i)

        for i in bst:
            expected.append(i)
        self.assertEqual(bst.to_list(), expected)
예제 #6
0
    def test_pop(self):
        bst = pyset()
        with self.assertRaises(IndexError):
            bst.pop("Hello world")

        bst.add(2)
        with self.assertRaises(IndexError):
            bst.pop(4)
        bst.pop(2)
        self.assertEqual(bst.to_list(), [])
예제 #7
0
 def test_add(self):
     bst = pyset()
     try:
         bst.add(3.0)
         bst.add(7)
         bst.add("lol")
         self.assertEqual(bst.size(), 3)
         with self.assertRaises(TypeError):
             bst.add(3, 40)
     except:
         self.fail()
예제 #8
0
#!/usr/bin/env python3

from py_set import pyset
import time
import sys
import random

random_list = [random.randrange(-1000000, 2000000) for _ in range(1000000)]

pst = pyset()
st = set()
lst = list()

print()
print("*** Adding elements ***")
start = time.time()
for i in range(1000000):
    lst.append(i)
end = time.time() - start
print("List time on adding 10^6 items: %.2fms" % (end * 1000))

start = time.time()
for i in range(1000000):
    st.add(i)
end = time.time() - start
print("Set time on adding 10^6 items: %.2fms" % (end * 1000))

start = time.time()
for i in range(1000000):
    pst.add(i)
end = time.time() - start
예제 #9
0
 def test_clear(self):
     bst = pyset(4, 100, 10)
     bst.clear()
     self.assertEqual(bst.to_list(), [])
예제 #10
0
 def test_to_list(self):
     bst = pyset()
     bst.add(48)
     bst.add(38.4)
     self.assertEqual(bst.to_list(), [38.4, 48])
예제 #11
0
 def test_size(self):
     bst = pyset()
     self.assertEqual(bst.size(), 0)
     for i in range(10):
         bst.add(i)
     self.assertEqual(bst.size(), 10)
예제 #12
0
 def test_max_size(self):
     bst = pyset()
     try:
         bst.max_size()
     except:
         self.fail()
예제 #13
0
 def test_creating_instance(self):
     try:
         bst = pyset()
     except Exception:
         self.fail("Can't create an instance of BST")
예제 #14
0
    def test_is_empty(self):
        bst = pyset()
        self.assertEqual(bst.is_empty(), 1)
        bst.add(3)

        self.assertEqual(bst.is_empty(), 0)
예제 #15
0
 def test_remove(self):
     l = range(1, 100)
     bst = pyset(1, 100)
     bst.remove(40)
     bst.remove("Not in pyset")
     self.assertEqual(bst.size(), len(list(l)) - 1)
예제 #16
0
 def test_find(self):
     bst = pyset()
     bst.add("lol")
     self.assertEqual(bst.find("lol"), 1)
     self.assertEqual(bst.find(38450), 0)
예제 #17
0
 def test_len(self):
     bst = pyset(100)
     self.assertEqual(len(bst), 100)
예제 #18
0
 def test_getitem(self):
     bst = pyset(10)
     self.assertEqual(bst[0], 0)
     self.assertEqual(bst[5], 5)
     self.assertEqual(bst[9], 9)
예제 #19
0
 def test_contains_method(self):
     bst = pyset(100)
     res = "NOT IN PYSET" in bst
     self.assertEqual(res, 0)
     res = 10 in bst
     self.assertEqual(res, 1)