github.com/korsakjakub/snk@v0.0.0-20230625212658-1d6c119c67ee/actor_test.go (about)

     1  package main
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestContains(t *testing.T) {
     8  	snake := actor{s: shape{{x: 0, y: 0}, {x: 1, y: 0}, {x: 2, y: 0}}, r: '#'}
     9  	fruit1 := actor{s: shape{{x: 0, y: 1}}, r: '*'}
    10  	fruit2 := actor{s: shape{{x: 1, y: 0}}, r: '*'}
    11  	fruit3 := actor{s: shape{{x: 0, y: 0}}, r: '*'}
    12  
    13  	if snake.s.contains(fruit1.s[0]) {
    14  		t.Errorf("snake %v shouldn't be eating fruit %v", snake, fruit1)
    15  	}
    16  	if !snake.s.contains(fruit2.s[0]) {
    17  		t.Errorf("snake %v should be eating fruit %v", snake, fruit2)
    18  	}
    19  	if !snake.s.contains(fruit3.s[0]) {
    20  		t.Errorf("snake %v should be eating fruit %v", snake, fruit3)
    21  	}
    22  }