github.com/frodejac/aoc-2022@v0.0.0-20221213081734-037c741b1c89/pkg/arraytools/arraytools_test.go (about)

     1  package arraytools
     2  
     3  import "testing"
     4  
     5  func TestSum(t *testing.T) {
     6  	array := []int{1, 2, 3, 4, 5}
     7  	sum := Sum(array)
     8  	if sum != 15 {
     9  		t.Errorf("Expected sum to be 15, got %d", sum)
    10  	}
    11  }
    12  
    13  func TestMax(t *testing.T) {
    14  	array := []int{1, 2, 3, 4, 5}
    15  	max := Max(array)
    16  	if max != 5 {
    17  		t.Errorf("Expected max to be 5, got %d", max)
    18  	}
    19  }
    20  
    21  func TestMin(t *testing.T) {
    22  	array := []int{1, 2, 3, 4, 5}
    23  	min := Min(array)
    24  	if min != 1 {
    25  		t.Errorf("Expected min to be 1, got %d", min)
    26  	}
    27  }
    28  
    29  func TestIntersect(t *testing.T) {
    30  	a := []int{1, 2, 3, 4, 5}
    31  	b := []int{3, 4, 5, 6, 7}
    32  	intersection := Intersect(a, b)
    33  	if len(intersection) != 3 {
    34  		t.Errorf("Expected intersection to be [3, 4, 5], got %v", intersection)
    35  	}
    36  }