libStatGen Software  1
TestPosList.cpp
00001 /*
00002  *  Copyright (C) 2011  Regents of the University of Michigan
00003  *
00004  *   This program is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #include "TestPosList.h"
00018 #include <assert.h>
00019 #include <stdexcept>
00020 
00021 
00022 void testPosList()
00023 {
00024     TestPosList posListTest;
00025     posListTest.testPosList();
00026 }
00027 
00028 TestPosList::TestPosList()
00029 {
00030 }
00031 
00032 
00033 TestPosList::~TestPosList()
00034 {
00035 }
00036 
00037 
00038 void TestPosList::testPosList()
00039 {
00040     assert(myPosList.size() == 24);
00041     
00042     for(int i = 0; i < 24; i++)
00043     {
00044         assert(myPosList.at(i).size() == 100);
00045     }
00046 
00047     bool caught = false;
00048     try
00049     {
00050         myPosList.at(24);
00051     }
00052     catch(std::out_of_range& oor)
00053     {
00054         caught = true;
00055     }
00056 
00057     assert(caught == true);
00058 
00059     //////////////////////////////
00060     // Test accessing
00061     for(int i = 0; i < 24; i++)
00062     {
00063         for(int j = 0; j < 100; j++)
00064         {
00065             assert(!hasPosition(i, j));
00066         }
00067     }
00068 
00069     //////////////////////////////
00070     // Test setting all
00071     for(int i = 0; i < 24; i++)
00072     {
00073         for(int j = 0; j < 100; j++)
00074         {
00075             addPosition(i, j);
00076         }
00077     }
00078     for(int i = 0; i < 24; i++)
00079     {
00080         for(int j = 0; j < 100; j++)
00081         {
00082             assert(hasPosition(i, j));
00083         }
00084     }
00085 
00086 
00087 
00088 
00089     //////////////////////////////
00090     // Test accessing out of range
00091     assert(!hasPosition(-1, 0));
00092     assert(!hasPosition(0, -1));
00093     assert(!hasPosition(100, 0));
00094     assert(!hasPosition(0, 1000));
00095 
00096     //////////////////////////////
00097     // Test adding more to ref 4,
00098     // but skipping positions.
00099     for(int j = 300; j < 350; j++)
00100     {
00101         addPosition(4, j);
00102     }
00103     for(int j = 0; j < 100; j++)
00104     {
00105         assert(hasPosition(4, j));
00106     }
00107     for(int j = 100; j < 300; j++)
00108     {
00109         assert(!hasPosition(4, j));
00110     }
00111     for(int j = 300; j < 350; j++)
00112     {
00113         assert(hasPosition(4, j));
00114     }
00115 
00116     // Test adding a new reference, 30,
00117     // position 16.
00118     addPosition(30, 16);
00119 
00120     // Check the size now.
00121     assert(myPosList.size() == 31);
00122     
00123     for(int i = 0; i < 24; i++)
00124     {
00125         if(i != 4)
00126         {
00127             assert(myPosList.at(i).size() == 100);
00128         }
00129         else
00130         {
00131             assert(myPosList.at(i).size() == 350);
00132         }
00133     }
00134 
00135     for(int i = 24; i < 31; i++)
00136     {
00137         assert(myPosList.at(i).size() == 350);
00138     }
00139 
00140     //////////////////////////////
00141     // Test accessing
00142     for(int i = 24; i < 30; i++)
00143     {
00144         for(int j = 0; j < 350; j++)
00145         {
00146             assert(!hasPosition(i, j));
00147         }
00148     }
00149     for(int j = 0; j < 350; j++)
00150     {
00151         if(j != 16)
00152         {
00153             assert(!hasPosition(30, j));
00154         }
00155         else
00156         {
00157             assert(hasPosition(30, 16));
00158         }
00159     }
00160 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends