* ***************************************************************************** Codon Compromise + Add related tests begin here. ***************************************************************************** */
(t *testing.T)
| 241 | ***************************************************************************** |
| 242 | */ |
| 243 | func TestCompromiseCodonTable(t *testing.T) { |
| 244 | sequence, _ := genbank.Read("../../data/puc19.gbk") |
| 245 | |
| 246 | // weight our codon optimization table using the regions we collected from the genbank file above |
| 247 | |
| 248 | optimizationTable, err := NewTranslationTable(11) |
| 249 | if err != nil { |
| 250 | t.Fatalf("failed to initialise codon table: %s", err) |
| 251 | } |
| 252 | |
| 253 | err = optimizationTable.UpdateWeightsWithSequence(sequence) |
| 254 | if err != nil { |
| 255 | t.Error(err) |
| 256 | } |
| 257 | |
| 258 | sequence2, _ := genbank.Read("../../data/phix174.gb") |
| 259 | optimizationTable2, err := NewTranslationTable(11) |
| 260 | if err != nil { |
| 261 | t.Fatalf("failed to initialise codon table: %s", err) |
| 262 | } |
| 263 | |
| 264 | err = optimizationTable2.UpdateWeightsWithSequence(sequence2) |
| 265 | if err != nil { |
| 266 | t.Error(err) |
| 267 | } |
| 268 | |
| 269 | _, err = CompromiseCodonTable(optimizationTable, optimizationTable2, -1.0) // Fails too low |
| 270 | if err == nil { |
| 271 | t.Errorf("Compromise table should fail on -1.0") |
| 272 | } |
| 273 | _, err = CompromiseCodonTable(optimizationTable, optimizationTable2, 10.0) // Fails too high |
| 274 | if err == nil { |
| 275 | t.Errorf("Compromise table should fail on 10.0") |
| 276 | } |
| 277 | |
| 278 | // replace chooser fn with test one |
| 279 | newChooserFn = func(choices ...weightedRand.Choice) (*weightedRand.Chooser, error) { |
| 280 | return nil, errors.New("new chooser rigged to fail") |
| 281 | } |
| 282 | |
| 283 | defer func() { |
| 284 | newChooserFn = weightedRand.NewChooser |
| 285 | }() |
| 286 | |
| 287 | _, err = CompromiseCodonTable(optimizationTable, optimizationTable2, 0.1) |
| 288 | if err == nil { |
| 289 | t.Errorf("Compromise table should fail when new chooser func rigged") |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | func TestAddCodonTable(t *testing.T) { |
| 294 | sequence, _ := genbank.Read("../../data/puc19.gbk") |
nothing calls this directly
no test coverage detected