-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorting_test.go
More file actions
113 lines (105 loc) · 2.64 KB
/
sorting_test.go
File metadata and controls
113 lines (105 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"reflect"
"sort"
"testing"
)
// Test sorting functionality
func TestQualityFloatListSorting(t *testing.T) {
tests := []struct {
name string
items []QualityFloat
ascending bool
metric QualityMetric
want []string // Expected order of names after sorting
}{
{
name: "AvgPhred Descending",
items: []QualityFloat{
{Name: "seq1", Value: 30.0, Metric: AvgPhred},
{Name: "seq2", Value: 40.0, Metric: AvgPhred},
{Name: "seq3", Value: 20.0, Metric: AvgPhred},
},
ascending: false,
metric: AvgPhred,
want: []string{"seq2", "seq1", "seq3"},
},
{
name: "MaxEE Ascending",
items: []QualityFloat{
{Name: "seq1", Value: 0.1, Metric: MaxEE},
{Name: "seq2", Value: 0.01, Metric: MaxEE},
{Name: "seq3", Value: 1.0, Metric: MaxEE},
},
ascending: true,
metric: MaxEE,
want: []string{"seq3", "seq1", "seq2"},
},
{
name: "MaxEE - Equal values, natural sort by name",
items: []QualityFloat{
{Name: "seq10", Value: 0.1, Metric: MaxEE},
{Name: "seq2", Value: 0.1, Metric: MaxEE},
{Name: "seq1", Value: 0.1, Metric: MaxEE},
},
ascending: false,
metric: MaxEE,
want: []string{"seq1", "seq2", "seq10"},
},
{
name: "Meep - Mixed values ascending",
items: []QualityFloat{
{Name: "seq1", Value: 5.0, Metric: Meep},
{Name: "seq2", Value: 2.0, Metric: Meep},
{Name: "seq3", Value: 10.0, Metric: Meep},
},
ascending: true,
metric: Meep,
want: []string{"seq3", "seq1", "seq2"},
},
{
name: "LQPercent - Zero values",
items: []QualityFloat{
{Name: "seq1", Value: 0.0, Metric: LQPercent},
{Name: "seq2", Value: 0.0, Metric: LQPercent},
},
ascending: false,
metric: LQPercent,
want: []string{"seq1", "seq2"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
list := NewQualityFloatList(tt.items, tt.ascending)
sort.Sort(list)
got := make([]string, len(list.items))
for i, item := range list.items {
got[i] = item.Name
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Sort() got %v, want %v", got, tt.want)
}
})
}
}
// Test quality metric string representation
func TestQualityMetricString(t *testing.T) {
tests := []struct {
metric QualityMetric
want string
}{
{AvgPhred, "avgphred"},
{MaxEE, "maxee"},
{Meep, "meep"},
{LQCount, "lqcount"},
{LQPercent, "lqpercent"},
{QualityMetric(999), "unknown"},
}
for _, tt := range tests {
t.Run(tt.want, func(t *testing.T) {
if got := tt.metric.String(); got != tt.want {
t.Errorf("QualityMetric.String() = %v, want %v", got, tt.want)
}
})
}
}