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 { {Path: []graph.ID{"0", "1"}},
name string {Path: []graph.ID{"0", "2"}},
walks []Walk {Path: []graph.ID{"0", "3"}},
toRemove []Walk {Path: []graph.ID{"1", "0"}},
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", "2"}},
{Path: []graph.ID{"0", "3"}},
{Path: []graph.ID{"1", "0"}},
},
toRemove: []Walk{
{Path: []graph.ID{"0", "1"}},
{Path: []graph.ID{"0", "2"}},
{Path: []graph.ID{"0", "3"}},
},
},
} }
for _, test := range tests { expected := []Walk{
t.Run(test.name, func(t *testing.T) { {Path: []graph.ID{"0", "1"}},
toRemove, err := ToRemove("0", test.walks) {Path: []graph.ID{"0", "2"}},
if !errors.Is(err, test.err) { {Path: []graph.ID{"0", "3"}},
t.Fatalf("expected error %v, got %v", test.err, err) }
}
if !reflect.DeepEqual(toRemove, test.toRemove) { toRemove, err := ToRemove("0", walks)
t.Fatalf("expected walks to remove %v, got %v", test.toRemove, toRemove) if err != nil {
} t.Fatalf("expected error nil, got %v", err)
}) }
if !reflect.DeepEqual(toRemove, expected) {
t.Fatalf("expected walks to remove %v, got %v", expected, toRemove)
} }
} }