summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jiyong Park <jiyong@google.com> 2024-12-30 16:00:22 +0900
committer Jiyong Park <jiyong@google.com> 2024-12-30 17:14:32 +0900
commit7683491c3f7b6e54032abd38f29c7fc471790744 (patch)
treedd0c66e6c8b903990c9df22be7e08d401200951c
parent8bb77bc8d2529e05430874b5fddfee30929a7445 (diff)
Add AssertSameArray
It is a generic version of AssertArrayString. Bug: N/A Test: build Change-Id: Ic863afaa4d18954efbe5a7b911463186f74f92ef
-rw-r--r--android/test_asserts.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/android/test_asserts.go b/android/test_asserts.go
index c33ade5a2..22472c5c2 100644
--- a/android/test_asserts.go
+++ b/android/test_asserts.go
@@ -33,6 +33,23 @@ func AssertSame(t *testing.T, message string, expected interface{}, actual inter
}
}
+// AssertSame checks if the expected and actual values are equal and if they are not then
+// it reports an error prefixed with the supplied message and including a reason for why it failed.
+func AssertSameArray[T comparable](t *testing.T, message string, expected []T, actual []T) {
+ t.Helper()
+ if len(actual) != len(expected) {
+ t.Errorf("%s: expected %d (%v), actual (%d) %v", message, len(expected), expected, len(actual), actual)
+ return
+ }
+ for i := range actual {
+ if actual[i] != expected[i] {
+ t.Errorf("%s: expected %d-th, %v (%v), actual %v (%v)",
+ message, i, expected[i], expected, actual[i], actual)
+ return
+ }
+ }
+}
+
// AssertBoolEquals checks if the expected and actual values are equal and if they are not then it
// reports an error prefixed with the supplied message and including a reason for why it failed.
func AssertBoolEquals(t *testing.T, message string, expected bool, actual bool) {