(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestDrain_PruneTreeClearsOldBranches(t *testing.T) { |
| 11 | t.Parallel() |
| 12 | |
| 13 | inputLines := []string{ |
| 14 | "test test test 123", |
| 15 | "test test test 456", |
| 16 | "test test test 789", |
| 17 | "test test test 101", |
| 18 | "my name is 104", |
| 19 | "my name is 105", |
| 20 | "my name is 106", |
| 21 | "my name is 107", |
| 22 | } |
| 23 | |
| 24 | drain := New("test-tenant", DefaultConfig()) |
| 25 | |
| 26 | for _, line := range inputLines { |
| 27 | drain.Train(line) |
| 28 | } |
| 29 | |
| 30 | require.Len(t, drain.Clusters(), 2) |
| 31 | require.Equal(t, 16, countNodes(drain.rootNode)) |
| 32 | |
| 33 | // Delete a cluster manually |
| 34 | drain.idToCluster.Remove(1) |
| 35 | require.Len(t, drain.Clusters(), 1) |
| 36 | require.Equal(t, 16, countNodes(drain.rootNode), "expected same number of nodes before pruning") |
| 37 | |
| 38 | drain.Prune() |
| 39 | require.Len(t, drain.Clusters(), 1) |
| 40 | require.Equal(t, 9, countNodes(drain.rootNode), "expected fewer nodes after pruning") |
| 41 | } |
| 42 | |
| 43 | func countNodes(node *Node) int { |
| 44 | total := 1 |
nothing calls this directly
no test coverage detected