Skip to content

Commit

Permalink
Update NN test formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
biotinker committed Nov 15, 2024
1 parent cf82763 commit 65da6bc
Showing 1 changed file with 5 additions and 30 deletions.
35 changes: 5 additions & 30 deletions motionplan/nearestNeighbor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,54 +17,29 @@ func TestNearestNeighbor(t *testing.T) {
nm := &neighborManager{nCPU: 2, parallelNeighbors: 1000}
rrtMap := map[node]node{}

j := &basicNode{
q: map[string][]referenceframe.Input{"": {{0.0}}},
cost: math.NaN(),
poses: PathStep{},
corner: false,
}
j := &basicNode{q: map[string][]referenceframe.Input{"": {{0.0}}}}
// We add ~110 nodes to the set of candidates. This is smaller than the configured
// `parallelNeighbors` or 1000 meaning the `nearestNeighbor` call will be evaluated in series.
for i := 1.0; i < 110.0; i++ {
iSol := &basicNode{
q: map[string][]referenceframe.Input{"": {{i}}},
cost: math.NaN(),
poses: PathStep{},
corner: false,
}
iSol := &basicNode{q: map[string][]referenceframe.Input{"": {{i}}}}
rrtMap[iSol] = j
j = iSol
}
ctx := context.Background()

seed := map[string][]referenceframe.Input{"": {{23.1}}}
opt := newBasicPlannerOptions()
nn := nm.nearestNeighbor(ctx, opt, &basicNode{
q: seed,
cost: math.NaN(),
poses: PathStep{},
corner: false,
}, rrtMap)
nn := nm.nearestNeighbor(ctx, opt, &basicNode{q: seed}, rrtMap)
test.That(t, nn.Q()[""][0].Value, test.ShouldAlmostEqual, 23.0)

// We add more nodes to trip the 1000 threshold. The `nearestNeighbor` call will use `nCPU` (2)
// goroutines for evaluation.
for i := 120.0; i < 1100.0; i++ {
iSol := &basicNode{
q: map[string][]referenceframe.Input{"": {{i}}},
cost: math.NaN(),
poses: PathStep{},
corner: false,
}
iSol := &basicNode{q: map[string][]referenceframe.Input{"": {{i}}}}
rrtMap[iSol] = j
j = iSol
}
seed = map[string][]referenceframe.Input{"": {{723.6}}}
nn = nm.nearestNeighbor(ctx, opt, &basicNode{
q: seed,
cost: math.NaN(),
poses: PathStep{},
corner: false,
}, rrtMap)
nn = nm.nearestNeighbor(ctx, opt, &basicNode{q: seed}, rrtMap)
test.That(t, nn.Q()[""][0].Value, test.ShouldAlmostEqual, 724.0)
}

0 comments on commit 65da6bc

Please sign in to comment.