Skip to content

Commit

Permalink
Updating assert as util and a separate test for all Assert* methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rajagopal28 committed Aug 1, 2021
1 parent 2b3aa08 commit 756bbc6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
19 changes: 12 additions & 7 deletions test/util/assert.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package util

import (
"log"
"testing"
"reflect"
)


func TestAssert(t *testing.T) {
log.Println("Some testing here!")
AssertEqual(1, 1, t)
AssertEqual([1]int{1}, [1]int{1}, t)
}

func AssertEqual(a interface{}, b interface{}, t *testing.T) {
if reflect.DeepEqual(a, b) {
return
}
t.Errorf("Received %v (type %v), expected %v (type %v)", a, reflect.TypeOf(a), b, reflect.TypeOf(b))
}


func AssertTrue(a bool, t *testing.T) {
if a {
return
}
t.Errorf("Received %v (type %v), expected %v (type %v)", a, reflect.TypeOf(a), !a, reflect.TypeOf(a))
}

func AssertFalse(a bool, t *testing.T) {
AssertTrue(!a, t)
}
16 changes: 16 additions & 0 deletions test/util/assert_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package util


import (
"log"
"testing"
)


func TestAssert(t *testing.T) {
log.Println("Some testing here!")
AssertEqual(1, 1, t)
AssertEqual([1]int{1}, [1]int{1}, t)
AssertTrue(true, t)
AssertFalse(false, t)
}

0 comments on commit 756bbc6

Please sign in to comment.