Commit a75d6b3c authored by Boris Mühmer's avatar Boris Mühmer
Browse files

added naming of objects at various levels

parent 816ca9af
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package wator

// Celler is just a simple cell.
type Celler interface {
	Name() string
	String() string
}

+6 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ type Fish struct {
}

const (
	name = "Fish"
	fish = "·" // "f" // "🐟"
)

@@ -16,6 +17,11 @@ func New(age int) *Fish {
	}
}

// Name returns the name.
func (f *Fish) Name() string {
	return name
}

// String return the representation.
func (f *Fish) String() string {
	return fish
+12 −8
Original line number Diff line number Diff line
@@ -9,17 +9,21 @@ func TestFish(t *testing.T) {
		t.Errorf("failed to create a new fish")
	}

	if ss := f.String(); ss != fish {
		t.Errorf("f.String() = %s, expected %s", ss, fish)
	if fn := f.Name(); fn != name {
		t.Errorf("f.Name() is %q, expected %q", fn, name)
	}

	if a := f.Age(); a != 0 {
		t.Errorf("f.Age() = %d, expected 0", a)
	if fs := f.String(); fs != fish {
		t.Errorf("f.String() = %s, expected %s", fs, fish)
	}

	n := 42
	f.SetAge(n)
	if a := f.Age(); a != n {
		t.Errorf("f.Age() = %d, expected %d", a, n)
	if fa := f.Age(); fa != 0 {
		t.Errorf("f.Age() = %d, expected 0", fa)
	}

	na := 42
	f.SetAge(na)
	if fa := f.Age(); fa != na {
		t.Errorf("f.Age() = %d, expected %d", fa, na)
	}
}
+6 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ type Shark struct {
}

const (
	name  = "Shark"
	shark = "O" // "S" // "🦈"
)

@@ -18,6 +19,11 @@ func New(age, ate int) *Shark {
	}
}

// Name ...
func (s *Shark) Name() string {
	return name
}

// String return the representation.
func (s *Shark) String() string {
	var i string
+7 −3
Original line number Diff line number Diff line
@@ -9,6 +9,10 @@ func TestShark(t *testing.T) {
		t.Errorf("failed to create a new shark")
	}

	if sn := s.Name(); sn != name {
		t.Errorf("s.Name() is %q, expected %q", sn, name)
	}

	for _, tv := range []struct {
		a int
		s string
@@ -23,21 +27,21 @@ func TestShark(t *testing.T) {
	} {
		s.SetAge(tv.a)
		if si := s.String(); si != tv.s {
			t.Errorf("s.String() = %s, expected %s", si, tv.s)
			t.Errorf("s.String() is %q, expected %q", si, tv.s)
		}
	}

	for _, ta := range []int{0, 42} {
		s.SetAge(ta)
		if a := s.Age(); a != ta {
			t.Errorf("s.Age() = %d, expected %d", a, ta)
			t.Errorf("s.Age() is %d, expected %d", a, ta)
		}
	}

	for _, ta := range []int{0, 42} {
		s.SetAte(ta)
		if a := s.Ate(); a != ta {
			t.Errorf("s.Ate() = %d, expected %d", a, ta)
			t.Errorf("s.Ate() is %d, expected %d", a, ta)
		}
	}
}
Loading