| 1 |
// Copyright 2025 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
//go:build riscv64 |
| 6 |
|
| 7 |
package testminmax |
| 8 |
|
| 9 |
import ( |
| 10 |
"testing" |
| 11 |
) |
| 12 |
|
| 13 |
func testMIN1(a int64) (r int64) |
| 14 |
func testMIN2(a, b int64) (r int64) |
| 15 |
func testMIN3(a, b int64) (r int64) |
| 16 |
func testMIN4(a, b int64) (r int64) |
| 17 |
func testMAX1(a int64) (r int64) |
| 18 |
func testMAX2(a, b int64) (r int64) |
| 19 |
func testMAX3(a, b int64) (r int64) |
| 20 |
func testMAX4(a, b int64) (r int64) |
| 21 |
func testMINU1(a int64) (r int64) |
| 22 |
func testMINU2(a, b int64) (r int64) |
| 23 |
func testMINU3(a, b int64) (r int64) |
| 24 |
func testMINU4(a, b int64) (r int64) |
| 25 |
func testMAXU1(a int64) (r int64) |
| 26 |
func testMAXU2(a, b int64) (r int64) |
| 27 |
func testMAXU3(a, b int64) (r int64) |
| 28 |
func testMAXU4(a, b int64) (r int64) |
| 29 |
|
| 30 |
func TestMin(t *testing.T) { |
| 31 |
tests := []struct { |
| 32 |
a int64 |
| 33 |
b int64 |
| 34 |
want int64 |
| 35 |
}{ |
| 36 |
{1, 2, 1}, |
| 37 |
{2, 1, 1}, |
| 38 |
{2, 2, 2}, |
| 39 |
{1, -1, -1}, |
| 40 |
{-1, 1, -1}, |
| 41 |
} |
| 42 |
for _, test := range tests { |
| 43 |
if got := testMIN1(test.a); got != test.a { |
| 44 |
t.Errorf("Assembly testMIN1 %v = %v, want %v", test.a, got, test.a) |
| 45 |
} |
| 46 |
if got := testMIN2(test.a, test.b); got != test.want { |
| 47 |
t.Errorf("Assembly testMIN2 %v, %v = %v, want %v", test.a, test.b, got, test.want) |
| 48 |
} |
| 49 |
if got := testMIN3(test.a, test.b); got != test.want { |
| 50 |
t.Errorf("Assembly testMIN3 %v, %v = %v, want %v", test.a, test.b, got, test.want) |
| 51 |
} |
| 52 |
if got := testMIN4(test.a, test.b); got != test.want { |
| 53 |
t.Errorf("Assembly testMIN4 %v, %v = %v, want %v", test.a, test.b, got, test.want) |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
func TestMax(t *testing.T) { |
| 59 |
tests := []struct { |
| 60 |
a int64 |
| 61 |
b int64 |
| 62 |
want int64 |
| 63 |
}{ |
| 64 |
{1, 2, 2}, |
| 65 |
{2, 1, 2}, |
| 66 |
{2, 2, 2}, |
| 67 |
{1, -1, 1}, |
| 68 |
{-1, 1, 1}, |
| 69 |
} |
| 70 |
for _, test := range tests { |
| 71 |
if got := testMAX1(test.a); got != test.a { |
| 72 |
t.Errorf("Assembly testMAX1 %v = %v, want %v", test.a, got, test.a) |
| 73 |
} |
| 74 |
if got := testMAX2(test.a, test.b); got != test.want { |
| 75 |
t.Errorf("Assembly testMAX2 %v, %v = %v, want %v", test.a, test.b, got, test.want) |
| 76 |
} |
| 77 |
if got := testMAX3(test.a, test.b); got != test.want { |
| 78 |
t.Errorf("Assembly testMAX3 %v, %v = %v, want %v", test.a, test.b, got, test.want) |
| 79 |
} |
| 80 |
if got := testMAX4(test.a, test.b); got != test.want { |
| 81 |
t.Errorf("Assembly testMAX4 %v, %v = %v, want %v", test.a, test.b, got, test.want) |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
func TestMinU(t *testing.T) { |
| 87 |
tests := []struct { |
| 88 |
a int64 |
| 89 |
b int64 |
| 90 |
want int64 |
| 91 |
}{ |
| 92 |
{1, 2, 1}, |
| 93 |
{2, 1, 1}, |
| 94 |
{2, 2, 2}, |
| 95 |
{1, -1, 1}, |
| 96 |
{-1, 1, 1}, |
| 97 |
} |
| 98 |
for _, test := range tests { |
| 99 |
if got := testMINU1(test.a); got != test.a { |
| 100 |
t.Errorf("Assembly testMINU1 %v = %v, want %v", test.a, got, test.a) |
| 101 |
} |
| 102 |
if got := testMINU2(test.a, test.b); got != test.want { |
| 103 |
t.Errorf("Assembly testMINU2 %v, %v = %v, want %v", test.a, test.b, got, test.want) |
| 104 |
} |
| 105 |
if got := testMINU3(test.a, test.b); got != test.want { |
| 106 |
t.Errorf("Assembly testMINU3 %v, %v = %v, want %v", test.a, test.b, got, test.want) |
| 107 |
} |
| 108 |
if got := testMINU4(test.a, test.b); got != test.want { |
| 109 |
t.Errorf("Assembly testMINU4 %v, %v = %v, want %v", test.a, test.b, got, test.want) |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
func TestMaxU(t *testing.T) { |
| 115 |
tests := []struct { |
| 116 |
a int64 |
| 117 |
b int64 |
| 118 |
want int64 |
| 119 |
}{ |
| 120 |
{1, 2, 2}, |
| 121 |
{2, 1, 2}, |
| 122 |
{2, 2, 2}, |
| 123 |
{1, -1, -1}, |
| 124 |
{-1, 1, -1}, |
| 125 |
} |
| 126 |
for _, test := range tests { |
| 127 |
if got := testMAXU1(test.a); got != test.a { |
| 128 |
t.Errorf("Assembly testMAXU1 %v = %v, want %v", test.a, got, test.a) |
| 129 |
} |
| 130 |
if got := testMAXU2(test.a, test.b); got != test.want { |
| 131 |
t.Errorf("Assembly testMAXU2 %v, %v = %v, want %v", test.a, test.b, got, test.want) |
| 132 |
} |
| 133 |
if got := testMAXU3(test.a, test.b); got != test.want { |
| 134 |
t.Errorf("Assembly testMAXU3 %v, %v = %v, want %v", test.a, test.b, got, test.want) |
| 135 |
} |
| 136 |
if got := testMAXU4(test.a, test.b); got != test.want { |
| 137 |
t.Errorf("Assembly testMAXU4 %v, %v = %v, want %v", test.a, test.b, got, test.want) |
| 138 |
} |
| 139 |
} |
| 140 |
} |