//----------------------------------------------------------------------------- // t-eofitness.cpp // (c) GeNeura Team 1998 //----------------------------------------------------------------------------- #include // time #include // srand, rand #include // cout #include // eoFitness //----------------------------------------------------------------------------- class eoFloat: public eoFitness { public: eoFloat(const float x) { fitness = x; } eoFloat(const int x) { fitness = static_cast(x); } bool operator<(const eoFitness& other) const { const eoFloat& x = (const eoFloat&) other; return fitness < x.fitness; } operator float() const { return fitness; } void printOn(ostream& os) const { os << fitness; } void readFrom(istream& is) { is >> fitness; } private: float fitness; }; //----------------------------------------------------------------------------- main() { srand(time(0)); eoFloat a = static_cast(rand()) / RAND_MAX, b = static_cast(rand()) / RAND_MAX; cout.precision(2); unsigned repeat = 2; while (repeat--) { cout << "------------------------------------------------------" << endl; cout << "testing < "; if (a < b) cout << a << " < " << b << " is true" << endl; else cout << a << " < " << b << " is false" < "; if (a > b) cout << a << " > " << b << " is true" << endl; else cout << a << " > " << b << " is false" <