log when walks don't match the expected number

This commit is contained in:
pippellia-btc
2025-06-17 12:09:24 +02:00
parent 978494cb50
commit 24948b0429
2 changed files with 19 additions and 43 deletions

View File

@@ -5,6 +5,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"log"
"math/rand/v2" "math/rand/v2"
"slices" "slices"
@@ -184,9 +185,8 @@ func ToRemove(node graph.ID, walks []Walk) ([]Walk, error) {
} }
if len(toRemove) != N { if len(toRemove) != N {
return nil, fmt.Errorf("ToRemove: %w: %d", ErrInvalidRemoval, len(toRemove)) log.Printf("ToRemove: %v: %d", ErrInvalidRemoval, len(toRemove))
} }
return toRemove, nil return toRemove, nil
} }

View File

@@ -2,7 +2,6 @@ package walks
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"math" "math"
"reflect" "reflect"
@@ -56,49 +55,26 @@ func TestGenerate(t *testing.T) {
} }
func TestToRemove(t *testing.T) { func TestToRemove(t *testing.T) {
N = 3 walks := []Walk{
tests := []struct {
name string
walks []Walk
toRemove []Walk
err error
}{
{
name: "no walks",
err: ErrInvalidRemoval,
},
{
name: "too few walks to remove",
walks: []Walk{{Path: []graph.ID{"0", "1"}}},
err: ErrInvalidRemoval,
},
{
name: "valid",
walks: []Walk{
{Path: []graph.ID{"0", "1"}}, {Path: []graph.ID{"0", "1"}},
{Path: []graph.ID{"0", "2"}}, {Path: []graph.ID{"0", "2"}},
{Path: []graph.ID{"0", "3"}}, {Path: []graph.ID{"0", "3"}},
{Path: []graph.ID{"1", "0"}}, {Path: []graph.ID{"1", "0"}},
}, }
toRemove: []Walk{
expected := []Walk{
{Path: []graph.ID{"0", "1"}}, {Path: []graph.ID{"0", "1"}},
{Path: []graph.ID{"0", "2"}}, {Path: []graph.ID{"0", "2"}},
{Path: []graph.ID{"0", "3"}}, {Path: []graph.ID{"0", "3"}},
},
},
} }
for _, test := range tests { toRemove, err := ToRemove("0", walks)
t.Run(test.name, func(t *testing.T) { if err != nil {
toRemove, err := ToRemove("0", test.walks) t.Fatalf("expected error nil, got %v", err)
if !errors.Is(err, test.err) {
t.Fatalf("expected error %v, got %v", test.err, err)
} }
if !reflect.DeepEqual(toRemove, test.toRemove) { if !reflect.DeepEqual(toRemove, expected) {
t.Fatalf("expected walks to remove %v, got %v", test.toRemove, toRemove) t.Fatalf("expected walks to remove %v, got %v", expected, toRemove)
}
})
} }
} }