@@ -29,6 +29,7 @@ BenchmarkPlan/deep-24 380756 3103 ns/op 230 B/op 1
2929BenchmarkPlan/deep-24 337836 3519 ns/op 230 B/op 1 allocs/op
3030BenchmarkPlan/deep-24 420907 2831 ns/op 230 B/op 1 allocs/op
3131BenchmarkPlan/deep-24 444250 2716 ns/op 230 B/op 1 allocs/op
32+ BenchmarkPlan/deep-24 499970 2345 ns/op 211 B/op 1 allocs/op
3233
3334BenchmarkPlan/maze-24 37 31458708 ns/op 2702894 B/op 80711 allocs/op
3435BenchmarkPlan/maze-24 63 18643352 ns/op 1569536 B/op 51464 allocs/op
@@ -93,40 +94,44 @@ func TestNumericPlan(t *testing.T) {
9394
9495 plan , err := Plan (start , goal , actions )
9596 assert .NoError (t , err )
96- assert .Equal (t , []string {"Forage" , "Forage" , "Forage" , "Sleep" , "Forage" , "Forage" , "Sleep" , "Forage" , "Forage" , "Forage" , "Sleep" , "Eat" , " Forage" },
97+ assert .Equal (t , []string {"Forage" , "Forage" , "Forage" , "Sleep" , "Forage" , "Forage" , "Sleep" , "Forage" , "Forage" , "Forage" , "Sleep" , "Forage" },
9798 planOf (plan ))
99+
100+ //assert.Fail(t, "xxx")
98101}
99102
100103func TestMaze (t * testing.T ) {
101- start := StateOf ("A" )
102- goal := StateOf ("Z" )
103- actions := []Action {
104+ plan , err := Plan (StateOf ("A" ), StateOf ("Z" ), []Action {
104105 move ("A->B" ), move ("B->C" ), move ("C->D" ), move ("D->E" ), move ("E->F" ), move ("F->G" ),
105106 move ("G->H" ), move ("H->I" ), move ("I->J" ), move ("C->X1" ), move ("E->X2" ), move ("G->X3" ),
106107 move ("X1->D" ), move ("X2->F" ), move ("X3->H" ), move ("B->Y1" ), move ("D->Y2" ), move ("F->Y3" ),
107108 move ("Y1->C" ), move ("Y2->E" ), move ("Y3->G" ), move ("J->K" ), move ("K->L" ), move ("L->M" ),
108109 move ("M->N" ), move ("N->O" ), move ("O->P" ), move ("P->Q" ), move ("Q->R" ), move ("R->S" ),
109110 move ("S->T" ), move ("T->U" ), move ("U->V" ), move ("V->W" ), move ("W->X" ), move ("X->Y" ),
110111 move ("Y->Z" ), move ("U->Z1" ), move ("W->Z2" ), move ("Z1->V" ), move ("Z2->X" ), move ("A->Z3" ),
111- }
112-
113- plan , err := Plan (start , goal , actions )
112+ })
114113 assert .NoError (t , err )
115114 assert .Equal (t , []string {"A->B" , "B->C" , "C->D" , "D->E" , "E->F" , "F->G" , "G->H" , "H->I" , "I->J" ,
116115 "J->K" , "K->L" , "L->M" , "M->N" , "N->O" , "O->P" , "P->Q" , "Q->R" , "R->S" , "S->T" , "T->U" , "U->V" ,
117116 "V->W" , "W->X" , "X->Y" , "Y->Z" },
118117 planOf (plan ))
118+ //assert.Fail(t, "xxx")
119119}
120120
121- func TestSimplePlan (t * testing.T ) {
122- start := StateOf ("A" , "B" )
123- goal := StateOf ("C" , "D" )
124- actions := []Action {move ("A->C" ), move ("A->D" ), move ("B->C" ), move ("B->D" )}
121+ func TestWeightedPlan (t * testing.T ) {
122+ plan , err := Plan (StateOf ("A" , "B" ), StateOf ("C" , "D" ),
123+ []Action {move ("A->C" ), move ("A->D" , 0.5 ), move ("B->C" ), move ("B->D" , 0.75 )},
124+ )
125+ assert .NoError (t , err )
126+ assert .Equal (t , []string {"A->D" , "B->C" }, planOf (plan ))
127+ }
125128
126- plan , err := Plan (start , goal , actions )
129+ func TestSimplePlan (t * testing.T ) {
130+ plan , err := Plan (StateOf ("A" , "B" ), StateOf ("C" , "D" ),
131+ []Action {move ("A->C" ), move ("A->D" ), move ("B->C" ), move ("B->D" )},
132+ )
127133 assert .NoError (t , err )
128- assert .Equal (t , []string {"A->C" , "B->D" },
129- planOf (plan ))
134+ assert .Equal (t , []string {"A->C" , "B->D" }, planOf (plan ))
130135}
131136
132137func TestNoPlanFound (t * testing.T ) {
@@ -139,9 +144,13 @@ func TestNoPlanFound(t *testing.T) {
139144
140145// ------------------------------------ Test Action ------------------------------------
141146
142- func move (m string ) Action {
147+ func move (m string , w ... float32 ) Action {
148+ if len (w ) == 0 {
149+ w = append (w , 1.0 )
150+ }
151+
143152 arr := strings .Split (m , "->" )
144- return actionOf (m , 1 , StateOf (arr [0 ]), StateOf ("!" + arr [0 ], arr [1 ]))
153+ return actionOf (m , w [ 0 ] , StateOf (arr [0 ]), StateOf ("!" + arr [0 ], arr [1 ]))
145154}
146155
147156func planOf (plan []Action ) []string {
0 commit comments