Loading cell.go→cell/cell.go +2 −2 Original line number Diff line number Diff line package wator package cell type celler interface { type Celler interface { String() string Age() int SetAge(int) Loading fish.go→cell/fish/fish.go +13 −3 Original line number Diff line number Diff line package wator package fish // Fish is the representation for a fish. type Fish struct { Loading @@ -6,12 +6,18 @@ type Fish struct { } const ( fish = "·" // "f" // "🐟" icon = "·" // "f" // "🐟" ) func New(age int) *Fish { return &Fish{ age: age, } } // String return the representation. func (f *Fish) String() string { return fish return icon } // Age returns the age of the fish. Loading @@ -23,3 +29,7 @@ func (f *Fish) Age() int { func (f *Fish) SetAge(a int) { f.age = a } func (f *Fish) AgeInc() { f.age++ } fish_test.go→cell/fish/fish_test.go +4 −4 Original line number Diff line number Diff line package wator package fish import "testing" func TestFish(t *testing.T) { f := &Fish{} f := New(0) if f == nil { t.Errorf("failed to create a new fish") } if ss := f.String(); ss != fish { t.Errorf("f.String() = %s, expected %s", ss, fish) if ss := f.String(); ss != icon { t.Errorf("f.String() = %s, expected %s", ss, icon) } if a := f.Age(); a != 0 { Loading shark.go→cell/shark/shark.go +22 −5 Original line number Diff line number Diff line package wator package shark // Shark is the representation for a shark. type Shark struct { Loading @@ -6,8 +6,17 @@ type Shark struct { ate int } func New(age int) *Shark { return &Shark{ age: age, ate: 0, } } const ( shark = "O" // "S" // "🦈" iconYoung = "o" icon = "O" // "S" // "🦈" iconOld = "0" ) // String return the representation. Loading @@ -15,11 +24,11 @@ func (s *Shark) String() string { var i string switch { case s.age < 10: i = "o" i = iconYoung case s.age < 20: i = "O" i = icon default: i = "0" i = iconOld } return i } Loading @@ -34,6 +43,10 @@ func (s *Shark) SetAge(a int) { s.age = a } func (s *Shark) AgeInc() { s.age++ } // Ate counts the chronos when shark ate the last time. func (s *Shark) Ate() int { return s.ate Loading @@ -43,3 +56,7 @@ func (s *Shark) Ate() int { func (s *Shark) SetAte(a int) { s.ate = a } func (s *Shark) AteInc() { s.ate++ } shark_test.go→cell/shark/shark_test.go +2 −2 Original line number Diff line number Diff line package wator package shark import "testing" func TestShark(t *testing.T) { s := &Shark{} s := New(0) if s == nil { t.Errorf("failed to create a new shark") Loading Loading
cell.go→cell/cell.go +2 −2 Original line number Diff line number Diff line package wator package cell type celler interface { type Celler interface { String() string Age() int SetAge(int) Loading
fish.go→cell/fish/fish.go +13 −3 Original line number Diff line number Diff line package wator package fish // Fish is the representation for a fish. type Fish struct { Loading @@ -6,12 +6,18 @@ type Fish struct { } const ( fish = "·" // "f" // "🐟" icon = "·" // "f" // "🐟" ) func New(age int) *Fish { return &Fish{ age: age, } } // String return the representation. func (f *Fish) String() string { return fish return icon } // Age returns the age of the fish. Loading @@ -23,3 +29,7 @@ func (f *Fish) Age() int { func (f *Fish) SetAge(a int) { f.age = a } func (f *Fish) AgeInc() { f.age++ }
fish_test.go→cell/fish/fish_test.go +4 −4 Original line number Diff line number Diff line package wator package fish import "testing" func TestFish(t *testing.T) { f := &Fish{} f := New(0) if f == nil { t.Errorf("failed to create a new fish") } if ss := f.String(); ss != fish { t.Errorf("f.String() = %s, expected %s", ss, fish) if ss := f.String(); ss != icon { t.Errorf("f.String() = %s, expected %s", ss, icon) } if a := f.Age(); a != 0 { Loading
shark.go→cell/shark/shark.go +22 −5 Original line number Diff line number Diff line package wator package shark // Shark is the representation for a shark. type Shark struct { Loading @@ -6,8 +6,17 @@ type Shark struct { ate int } func New(age int) *Shark { return &Shark{ age: age, ate: 0, } } const ( shark = "O" // "S" // "🦈" iconYoung = "o" icon = "O" // "S" // "🦈" iconOld = "0" ) // String return the representation. Loading @@ -15,11 +24,11 @@ func (s *Shark) String() string { var i string switch { case s.age < 10: i = "o" i = iconYoung case s.age < 20: i = "O" i = icon default: i = "0" i = iconOld } return i } Loading @@ -34,6 +43,10 @@ func (s *Shark) SetAge(a int) { s.age = a } func (s *Shark) AgeInc() { s.age++ } // Ate counts the chronos when shark ate the last time. func (s *Shark) Ate() int { return s.ate Loading @@ -43,3 +56,7 @@ func (s *Shark) Ate() int { func (s *Shark) SetAte(a int) { s.ate = a } func (s *Shark) AteInc() { s.ate++ }
shark_test.go→cell/shark/shark_test.go +2 −2 Original line number Diff line number Diff line package wator package shark import "testing" func TestShark(t *testing.T) { s := &Shark{} s := New(0) if s == nil { t.Errorf("failed to create a new shark") Loading