MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TestSimple

Function TestSimple

strings/genetic/geneticalgorithm_test.go:7–25  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

5)
6
7func TestSimple(t *testing.T) {
8 target := "This is a genetic algorithm to evaluate, combine, evolve and mutate a string!"
9 charmap := []rune(" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.,;!?+-*#@^'èéòà€ù=)(&%$£/\\")
10
11 res, err := GeneticString(target, charmap, &Conf{})
12 if err != nil {
13 t.Errorf("Unexpected error: %v\n", err)
14 }
15
16 got := res.Best
17
18 if got.Value != float64(1.0) {
19 t.Errorf("Target value not reached\nwant: %f\n, got: %f\n", float64(1.0), got.Value)
20 }
21
22 if got.Key != target {
23 t.Errorf("Target string not reached\nwant: %s\n, got: %s\n", target, got.Key)
24 }
25}

Callers

nothing calls this directly

Calls 1

GeneticStringFunction · 0.85

Tested by

no test coverage detected