(t *testing.T)
| 599 | } |
| 600 | |
| 601 | func TestCopy(t *testing.T) { |
| 602 | t.Parallel() |
| 603 | |
| 604 | cmpOptions := []cmp.Option{ |
| 605 | cmpopts.IgnoreUnexported(weightedRand.Chooser{}), |
| 606 | } |
| 607 | |
| 608 | tests := []struct { |
| 609 | name string |
| 610 | |
| 611 | wantErr error |
| 612 | }{ |
| 613 | { |
| 614 | name: "ok", |
| 615 | |
| 616 | wantErr: nil, |
| 617 | }, |
| 618 | } |
| 619 | |
| 620 | for _, tt := range tests { |
| 621 | var tt = tt |
| 622 | t.Run(tt.name, func(t *testing.T) { |
| 623 | t.Parallel() |
| 624 | |
| 625 | original, err := NewTranslationTable(11) |
| 626 | if err != nil { |
| 627 | t.Fatal(err) |
| 628 | } |
| 629 | |
| 630 | // perform a deep copy (changing the copy will not change the original) |
| 631 | |
| 632 | deepCopy, err := original.Copy() |
| 633 | if !errors.Is(err, tt.wantErr) { |
| 634 | t.Errorf("got %v, want %v", err, tt.wantErr) |
| 635 | } |
| 636 | |
| 637 | // modify fields |
| 638 | |
| 639 | deepCopy.StartCodons[0] = "🍌" |
| 640 | deepCopy.StopCodons[0] = "🐗" |
| 641 | deepCopy.AminoAcids = []AminoAcid{} |
| 642 | deepCopy.Choosers = map[string]weightedRand.Chooser{} |
| 643 | deepCopy.Stats = &Stats{} |
| 644 | deepCopy.TranslationMap = map[string]string{} |
| 645 | |
| 646 | // this compares pointers |
| 647 | if cmp.Equal(deepCopy, original, cmpOptions...) { |
| 648 | t.Errorf("deepCopy and original matched, we did not want them to %s", cmp.Diff(deepCopy, original, cmpOptions...)) |
| 649 | } |
| 650 | |
| 651 | // we compare the table's fields |
| 652 | |
| 653 | if cmp.Equal(deepCopy.StartCodonTable, original.StartCodons) { |
| 654 | t.Errorf("deepCopy and original matched, we did not want them to %s", cmp.Diff(deepCopy.StartCodonTable, original.StartCodons)) |
| 655 | } |
| 656 | |
| 657 | if cmp.Equal(deepCopy.StopCodons, original.StopCodons) { |
| 658 | t.Errorf("deepCopy and original matched, we did not want them to %s", cmp.Diff(deepCopy.StopCodons, original.StopCodons)) |
nothing calls this directly
no test coverage detected