//============================================================================== // // Copyright (C) 2006 Dick van Oudheusden // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public // License as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public // License along with this program; if not, write to the Free // Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // //============================================================================== // // $Date: 2006/09/20 17:46:00 $ $Revision: 1.1 $ // //============================================================================== #include #include #include "ofc/config.h" #include "ofc/DMRnd.h" #include "DInc.h" #include "DTest.h" //-Misc------------------------------------------------------------------------ void DMRnd_test() { DMRnd *rnd = [DMRnd new]; int cnt; STARTTEST(); // default seed TEST([rnd nextInt] == -795755684); // 3499211612 for (cnt = 0; cnt < 622; cnt++) { [rnd nextInt]; } TEST([rnd nextInt] == -274641409); // 4020325887 TEST([rnd nextInt] == -116073384); // 4178893912 TEST([rnd nextInt] == 610818241); for (cnt = 0; cnt < 9999; cnt++) { [rnd nextInt]; } TEST([rnd nextInt] == 862334504); [rnd free]; // create with seed rnd = [DMRnd alloc]; [rnd init :19650218]; TEST(fabs([rnd nextDouble] - 0.54146918) < 0.0000001); for (cnt = 0; cnt < 9999; cnt++) { [rnd nextDouble]; } TEST(fabs([rnd nextDouble] - 0.95790732) < 0.0000001); // range check for (cnt = 0; cnt < 500; cnt++) { int val = [rnd nextInt :10 :30]; TEST((val >= 10) && (val <= 30)); } for (cnt = 0; cnt < 500; cnt++) { double val = [rnd nextDouble :12.4 :12.5]; TEST((val >= 12.4) && (val < 12.5)); } [rnd free]; STOPTEST(); }