Commit a4ec396c authored by amitjans's avatar amitjans
Browse files

Remove previous tests

parent 2873d8c1
......@@ -20,12 +20,10 @@ endif()
add_library(Penna STATIC genome.cpp animal.cpp)
add_executable(genome-test test-genome.cpp)
add_executable(animal-test animal-test.cpp)
target_link_libraries(genome-test Penna)
target_link_libraries(animal-test Penna)
install(TARGETS genome-test animal-test DESTINATION bin)
install(TARGETS genome-test DESTINATION bin)
install(TARGETS Penna
ARCHIVE DESTINATION lib
......
/*
* This is the test program for the animal class.
*/
#include "animal.hpp"
#include <cassert>
#include <iostream>
void test (unsigned bad_threshold, unsigned maturity_age) {
Penna::Animal::set_bad_threshold(bad_threshold);
Penna::Animal::set_maturity_age(maturity_age);
Penna::Animal::set_probability_to_get_pregnant(1);
Penna::Genome genome;
for(std::size_t index=0; index < 1000; ++index) {
genome.mutate();
Penna::Animal animal(genome);
while(!animal.is_dead()) {
assert(genome.count_bad(animal.age()) <= bad_threshold);
if(animal.is_pregnant()) {
Penna::Animal child = animal.give_birth();
assert(child.age()==0);
assert(!child.is_pregnant());
}
animal.grow();
}
assert(animal.age() == Penna::Animal::maximum_age + 1 ||
genome.count_bad(animal.age()) == bad_threshold + 1);
}
}
int main() {
//seed the random number generator
srand(42);
// normal cases
test(4,1);
test(3,4);
test(2,5);
// boundary cases
test(0,5);
test(4,Penna::Animal::maximum_age);
test(Penna::Animal::maximum_age,6);
test(Penna::Animal::maximum_age,Penna::Animal::maximum_age);
std::cout << "Animal tests passed." << std::endl;
return 0;
}
/*
* This is the test program for the genome class.
*/
#include "genome.hpp"
#include <cassert>
#include <iostream>
void test(int M) {
Penna::Genome::set_mutation_rate(M);
Penna::Genome parent_g;
Penna::Genome child_g;
for(size_t index=0; index < 1000; ++index) {
child_g = Penna::Genome(parent_g);
child_g.mutate();
// Age a parent and child over their lifetime, tracking their difference.
// Check that child's count_bad differs at most by one per year.
// Check the current year's gene bit and keep track of the difference
// between parent and child. This should stay within the mutation rate.
// The child becomes the new parent for the next iteration.
int diff = child_g.count_bad(0) == parent_g.count_bad(0) ? 0 : 1;
for(size_t age = 1; age < Penna::Genome::number_of_genes; ++age) {
const size_t deletrious = child_g.count_bad(age);
const size_t deletrious_prev = child_g.count_bad(age-1);
assert( (deletrious_prev == deletrious) ||
(deletrious_prev+1 == deletrious) );
const size_t child_b = deletrious - deletrious_prev;
const size_t parent_b = parent_g.count_bad(age) - parent_g.count_bad(age-1);
if (parent_b != child_b) ++diff;
}
assert( diff <= M && (diff%2 == M%2) );
parent_g = child_g;
}
}
int main() {
// seed the random number generator
srand(42);
// run the test
for(size_t M = 1; M < 5; ++M)
test(M);
std::cout<<"Genome tests passed." << std::endl;
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment