This commit is contained in:
2026-06-27 05:28:43 -05:00
parent 290eb74573
commit 531bb53769
3 changed files with 631 additions and 14 deletions
+115 -2
View File
@@ -7,7 +7,7 @@ func TestParseArgsCPU(t *testing.T) {
if err != nil {
t.Fatalf("parseArgs returned error: %v", err)
}
if opts.kind != kindCPU || opts.query != "Ryzen 3600x" {
if opts.kind != kindCPU || len(opts.queries) != 1 || opts.queries[0] != "Ryzen 3600x" {
t.Fatalf("unexpected options: %+v", opts)
}
}
@@ -17,11 +17,115 @@ func TestParseArgsGPU(t *testing.T) {
if err != nil {
t.Fatalf("parseArgs returned error: %v", err)
}
if opts.kind != kindGPU || opts.query != "Radeon RX 6650 XT" {
if opts.kind != kindGPU || len(opts.queries) != 1 || opts.queries[0] != "Radeon RX 6650 XT" {
t.Fatalf("unexpected options: %+v", opts)
}
}
func TestParseArgsCPUCompare(t *testing.T) {
opts, err := parseArgs([]string{"--cpu", "Ryzen 3600x", "Core i7-10700"})
if err != nil {
t.Fatalf("parseArgs returned error: %v", err)
}
if opts.kind != kindCPU || len(opts.queries) != 2 || opts.queries[0] != "Ryzen 3600x" || opts.queries[1] != "Core i7-10700" {
t.Fatalf("unexpected options: %+v", opts)
}
}
func TestParseArgsCPUMany(t *testing.T) {
opts, err := parseArgs([]string{"--cpu", "Ryzen 3600x", "Core i7-10700", "Core i5-12400", "Ryzen 5800X3D"})
if err != nil {
t.Fatalf("parseArgs returned error: %v", err)
}
if opts.kind != kindCPU || len(opts.queries) != 4 {
t.Fatalf("unexpected options: %+v", opts)
}
want := []string{"Ryzen 3600x", "Core i7-10700", "Core i5-12400", "Ryzen 5800X3D"}
for i := range want {
if opts.queries[i] != want[i] {
t.Fatalf("query %d = %q, want %q; all options: %+v", i, opts.queries[i], want[i], opts)
}
}
}
func TestComparisonRowsMany(t *testing.T) {
results := []result{
{Kind: kindCPU, Name: "A", Stats: []stat{{Name: "PassMark Score", Value: "10"}, {Name: "Price", Value: "$300"}}},
{Kind: kindCPU, Name: "B", Stats: []stat{{Name: "PassMark Score", Value: "20"}, {Name: "Price", Value: "$200"}}},
{Kind: kindCPU, Name: "C", Stats: []stat{{Name: "PassMark Score", Value: "15"}, {Name: "Price", Value: "$250"}}},
}
rows := comparisonRows(results)
if len(rows) < 2 {
t.Fatalf("expected comparison rows, got %+v", rows)
}
score := findRow(rows, "PassMark Score")
if len(score) != 5 {
t.Fatalf("score row has %d cells, want 5: %+v", len(score), score)
}
if score[4] != "B" {
t.Fatalf("score winner = %q, want B; row: %+v", score[4], score)
}
price := findRow(rows, "Price")
if price[4] != "B" {
t.Fatalf("price winner = %q, want B; row: %+v", price[4], price)
}
}
func TestCompareStatPriceLowerIsBetter(t *testing.T) {
cmp, ok := compareStat("Price", "$97.71", "$299.99")
if !ok {
t.Fatal("expected price to compare")
}
if cmp <= 0 {
t.Fatalf("cmp = %d, want left price to win", cmp)
}
}
func TestCompareStatPassMarkHigherIsBetter(t *testing.T) {
cmp, ok := compareStat("PassMark Score", "18,123", "17,111")
if !ok {
t.Fatal("expected score to compare")
}
if cmp <= 0 {
t.Fatalf("cmp = %d, want left score to win", cmp)
}
}
func TestCompareStatReleaseDateNewerIsBetter(t *testing.T) {
cmp, ok := compareStat("CPU First Seen on Charts", "Jan 2024", "January 2021")
if !ok {
t.Fatal("expected release date to compare")
}
if cmp <= 0 {
t.Fatalf("cmp = %d, want newer date to win", cmp)
}
}
func TestCompareStatQuarterDateNewerIsBetter(t *testing.T) {
cmp, ok := compareStat("CPU First Seen on Charts", "Q3 2019", "Q2 2018")
if !ok {
t.Fatal("expected quarter date to compare")
}
if cmp <= 0 {
t.Fatalf("cmp = %d, want newer quarter to win", cmp)
}
}
func TestCompareStatSocketIsNotNumeric(t *testing.T) {
if _, ok := compareStat("Socket", "AM4", "FCLGA1200"); ok {
t.Fatal("socket values should not be treated as numeric comparisons")
}
}
func TestCanonicalDetailURLCPU(t *testing.T) {
got := canonicalDetailURL(kindCPU, "https://www.cpubenchmark.net/cpu_lookup.php?cpu=Intel+Core+i7&id=3747")
want := "https://www.cpubenchmark.net/cpu.php?cpu=Intel+Core+i7&id=3747"
if got != want {
t.Fatalf("canonicalDetailURL = %q, want %q", got, want)
}
}
func TestPassMarkSelectedStatsCPU(t *testing.T) {
html := `
<script>var cpuDetailsId = "3494";</script>
@@ -81,3 +185,12 @@ func assertStats(t *testing.T, stats []stat, want map[string]string) {
}
}
}
func findRow(rows [][]string, name string) []string {
for _, row := range rows {
if row[0] == name {
return row
}
}
return nil
}