?? test_binary_genotype.cpp
字號:
#include <iostream>#include <stdlib.h>#include <cpplibga/genotype/Binary.h>int main(void){ { typedef cpplibga::genotype::Binary<1> GT; GT b,c; if(GT::size()!=1){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;} b.setGene(0,true); if(b.getGene(0)!=true){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;} b.setGene(0,false); if(b.getGene(0)!=false){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;} b.invertGene(0); if(b.getGene(0)!=true){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;} c=b; if(!(c==b)){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;} } { typedef cpplibga::genotype::Binary<13> GT; GT b,c; if(GT::size()!=13){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;} for(unsigned long t=0;t<1000;t++) { unsigned long i=t%13; bool v=rand()<RAND_MAX/2; b.setGene(i,v); if(b.getGene(i)!=v){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;} b.invertGene(i); if(b.getGene(i)==v){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;} } c=b; if(!(c==b)){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;} for(unsigned long t=0;t<1000;t++) { unsigned long i=t%13; bool v=b.getGene(i); b.setGene(i,!v); if(c==b){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;} b.invertGene(i); if(!(c==b)){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;} b.invertGene(i); b.setGene(i,v); if(!(c==b)){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;} } } { typedef cpplibga::genotype::Binary<128> GT; GT b,c; if(GT::size()!=128){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;} for(unsigned long t=0;t<1000;t++) { unsigned long i=t%128; bool v=rand()<RAND_MAX/2; b.setGene(i,v); if(b.getGene(i)!=v){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;} b.invertGene(i); if(b.getGene(i)==v){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;} } c=b; if(!(c==b)){std::cout<<"Error at line "<<__LINE__<<std::endl;return -1;} } std::cout<<"Ok"<<std::endl; return 0;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -