Commit dc1afb06 authored by Boris Mühmer (ADESTIS)'s avatar Boris Mühmer (ADESTIS) 💬
Browse files

reorg of code

parent be8e91f6
Loading
Loading
Loading
Loading
+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)
+13 −3
Original line number Diff line number Diff line
package wator
package fish

// Fish is the representation for a fish.
type Fish struct {
@@ -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.
@@ -23,3 +29,7 @@ func (f *Fish) Age() int {
func (f *Fish) SetAge(a int) {
	f.age = a
}

func (f *Fish) AgeInc() {
	f.age++
}
+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 {
+22 −5
Original line number Diff line number Diff line
package wator
package shark

// Shark is the representation for a shark.
type Shark struct {
@@ -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.
@@ -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
}
@@ -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
@@ -43,3 +56,7 @@ func (s *Shark) Ate() int {
func (s *Shark) SetAte(a int) {
	s.ate = a
}

func (s *Shark) AteInc() {
	s.ate++
}
+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