def test_pons_asinorum(self): g0 = Graph.with_features( Equation.make_table(range(1, 20), range(1, 20), [plus, minus, times])) g1 = Graph.augment(PrefixedGraph(1, g0), PrefixedGraph(2, g0)) # print('QQ') # qq = list((x1, x1.with_prefix(2)) # for x1 in g1.query(WithPrefix(1, OfClass(After)))) # print(type(qq), type(qq[0]), len(qq[0])) # pts(qq) g = g1.add_edges( EnumEdges( Hops.from_pairs(*( (p_after, PrefixedNode(2, Before(p_after.unprefixed().x))) for p_after in g1.query(WithPrefix(1, OfClass(After))))))) #pts(g.query(WithPrefix(1, OfClass(After)))) #pts(g.query(WithPrefix(2, OfClass(Before)))) #pts(g.successors_of(PrefixedNode(1, After(10)))) #print() #pts(g.successors_of(PrefixedNode(1, After(63)))) self.assertTrue( g.find_hop(PrefixedNode(1, After(10)), PrefixedNode(2, Before(10)))) self.assertFalse( g.find_hop(PrefixedNode(1, After(63)), PrefixedNode(2, Before(63))))
def test_features(self): e = Equation.make([3, 4], plus) self.assertCountEqual(features_of(e), [ plus, 3, 4, 7, Before(3), Before(4), After(7), Increase, MaxBefore(4), MinBefore(3), NumOperands(2), Equation ])
def test_4_10(self): t0 = process_time() out_d = self.sl.dquery(features=[Before(4), After(10), Equation]) elapsed = process_time() - t0 self.assertEqual( self.sl.top1(out_d, pred=Equation), Equation.make([6, 4], plus) ) self.assertCountEqual( self.sl.top(out_d, pred=int, k=3), [6, 4, 10] ) self.assertLessEqual(elapsed, 5.0)
def test_backwash(self): # Pulsing an Equation should activate the nodes for its main # features. out_d = self.sl.dquery(features=[Equation.make([6, 4], plus)]) self.assertCountEqual( self.sl.top(out_d, pred=int, k=3), [6, 4, 10] ) self.assertEqual( self.sl.top1(out_d, pred=After), After(10) ) self.assertCountEqual( self.sl.top(out_d, pred=Before, k=2), [Before(6), Before(4)] )
print() pts(sl.topna(out_d, pred=Before, k=20)) print() pts(sl.topna(out_d, pred=After, k=20)) print() pts(sl.topna(out_d, pred=isclass, k=20)) print() pts(sl.topna(out_d, pred=Operator, k=20)) print() #print(out_d[NumOperands(2)]) #print(out_d[PrefixedNode(1, After(10))]) #print(out_d[PrefixedNode(2, Before(10))]) print(f'{t1 - t0:1.3f} sec') if __name__ == '__main__': run([Before(4), After(10), Equation], p=p1) #run([Before(4), Before(6), Equation, After], p=p1) #run([Equation.make([6, 4], plus)], p=p) #run([Before(4), Before(5), Before(6), After(15), NodeA(After, 10.0), Equation], p=p1) #run([Before(4), Before(5), Before(6), After(15), After, Equation], p=p1) #run([Before(4), Before(5), Before(6), After(15)]) #run([4, 5, 6, 15]) """ g2 = Graph.augment( PrefixedGraph(1, eqn_graph), PrefixedGraph(2, eqn_graph), ) hops = [] for p_after in g2.query(WithPrefix(1, OfClass(After))): hops.append(Hop(