Skip to content

Commit

Permalink
Change String method of Individual
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxHalford committed Nov 28, 2017
1 parent c5e5057 commit def1672
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions individual.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ func NewIndividual(genome Genome, rng *rand.Rand) Individual {
// String representation of an Individual. A tick (✔) or cross (✘) marker is
// added at the end to indicate if the Individual has been evaluated or not.
func (indi Individual) String() string {
var evalSymbol = map[bool]string{
true: "✔",
false: "✘",
}[indi.Evaluated]
return fmt.Sprintf("%s - %.3f - %v %s", indi.ID, indi.Fitness, indi.Genome, evalSymbol)
if indi.Evaluated {
return fmt.Sprintf("%s - %.3f - %v", indi.ID, indi.Fitness, indi.Genome)
}
return fmt.Sprintf("%s - ??? - %v", indi.ID, indi.Genome)
}

// Clone an individual to produce a new individual with a different pointer and
Expand Down
4 changes: 2 additions & 2 deletions individual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestIndividualString(t *testing.T) {
Evaluated: true,
ID: "bob",
},
str: "bob - 42.000 - [0 1 2]",
str: "bob - 42.000 - [0 1 2]",
},
{
indi: Individual{
Expand All @@ -26,7 +26,7 @@ func TestIndividualString(t *testing.T) {
Evaluated: false,
ID: "ALICE",
},
str: "ALICE - 42.000 - [0 1 2]",
str: "ALICE - ??? - [0 1 2]",
},
}
for i, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion individuals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestIndividualsString(t *testing.T) {
ID: "ALICE",
},
},
str: "bob - 42.000 - [0 1 2]\nALICE - 42.000 - [0 1 2]",
str: "bob - 42.000 - [0 1 2]\nALICE - ??? - [0 1 2]",
},
}
for i, tc := range testCases {
Expand Down

0 comments on commit def1672

Please sign in to comment.