Ejemplo n.º 1
0
 def get_random_dag(self,n,p):
     dag = DAG()
     for i in range(n):
         dag.add_element(i)
     arr = [ i for i in range(n) ]
     random.shuffle(arr)
     for i in range(n):
         for j in range(i+1,n):
             if random.random() < p:
                 dag.put_below(arr[i], arr[j])
     return dag
Ejemplo n.º 2
0
 def get_random_dag(self, n, p):
     dag = DAG()
     for i in range(n):
         dag.add_element(i)
     arr = [i for i in range(n)]
     random.shuffle(arr)
     for i in range(n):
         for j in range(i + 1, n):
             if random.random() < p:
                 dag.put_below(arr[i], arr[j])
     return dag
Ejemplo n.º 3
0
    def test_reachable_above(self):
        dag = DAG()
        for i in range(5):
            dag.add_element(i)
            self.assertEqual([i], sorted(dag.get_reachable_above(i)))
        for i in range(5):
            self.assertEqual([i], sorted(dag.get_reachable_above(i)))

        dag.put_below(3, 4)
        self.assertEqual([3], sorted(dag.get_reachable_above(3)))
        self.assertEqual([3,4], sorted(dag.get_reachable_above(4)))
        self.assertEqual([1], sorted(dag.get_reachable_above(1)))

        dag.put_below(1, 0)
        dag.put_below(2, 1)
        self.assertEqual([2], sorted(dag.get_reachable_above(2)))
        self.assertEqual([1,2], sorted(dag.get_reachable_above(1)))
        self.assertEqual([0,1,2], sorted(dag.get_reachable_above(0)))

        dag.put_below(2, 0)
        self.assertEqual([2], sorted(dag.get_reachable_above(2)))
        self.assertEqual([1,2], sorted(dag.get_reachable_above(1)))
        self.assertEqual([0,1,2], sorted(dag.get_reachable_above(0)))

        dag.put_below(4, 1)
        self.assertEqual([2], sorted(dag.get_reachable_above(2)))
        self.assertEqual([1,2,3,4], sorted(dag.get_reachable_above(1)))
        self.assertEqual([0,1,2,3,4], sorted(dag.get_reachable_above(0)))

        dag.put_below(4, 2)
        self.assertEqual([0,1,2,3,4], sorted(dag.get_reachable_above(0)))
        self.assertEqual([1,2,3,4], sorted(dag.get_reachable_above(1)))
        self.assertEqual([2,3,4], sorted(dag.get_reachable_above(2)))
        self.assertEqual([3], sorted(dag.get_reachable_above(3)))
        self.assertEqual([3,4], sorted(dag.get_reachable_above(4)))
Ejemplo n.º 4
0
    def test_reachable_above(self):
        dag = DAG()
        for i in range(5):
            dag.add_element(i)
            self.assertEqual([i], sorted(dag.get_reachable_above(i)))
        for i in range(5):
            self.assertEqual([i], sorted(dag.get_reachable_above(i)))

        dag.put_below(3, 4)
        self.assertEqual([3], sorted(dag.get_reachable_above(3)))
        self.assertEqual([3, 4], sorted(dag.get_reachable_above(4)))
        self.assertEqual([1], sorted(dag.get_reachable_above(1)))

        dag.put_below(1, 0)
        dag.put_below(2, 1)
        self.assertEqual([2], sorted(dag.get_reachable_above(2)))
        self.assertEqual([1, 2], sorted(dag.get_reachable_above(1)))
        self.assertEqual([0, 1, 2], sorted(dag.get_reachable_above(0)))

        dag.put_below(2, 0)
        self.assertEqual([2], sorted(dag.get_reachable_above(2)))
        self.assertEqual([1, 2], sorted(dag.get_reachable_above(1)))
        self.assertEqual([0, 1, 2], sorted(dag.get_reachable_above(0)))

        dag.put_below(4, 1)
        self.assertEqual([2], sorted(dag.get_reachable_above(2)))
        self.assertEqual([1, 2, 3, 4], sorted(dag.get_reachable_above(1)))
        self.assertEqual([0, 1, 2, 3, 4], sorted(dag.get_reachable_above(0)))

        dag.put_below(4, 2)
        self.assertEqual([0, 1, 2, 3, 4], sorted(dag.get_reachable_above(0)))
        self.assertEqual([1, 2, 3, 4], sorted(dag.get_reachable_above(1)))
        self.assertEqual([2, 3, 4], sorted(dag.get_reachable_above(2)))
        self.assertEqual([3], sorted(dag.get_reachable_above(3)))
        self.assertEqual([3, 4], sorted(dag.get_reachable_above(4)))