source: src/Helpers/unittests/RangeUnitTest.cpp@ 084729c

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 084729c was 084729c, checked in by Frederik Heber <heber@…>, 8 years ago

Squashed 'ThirdParty/CodePatterns/' content from commit c1e1041

git-subtree-dir: ThirdParty/CodePatterns
git-subtree-split: c1e10418c454f98be2f43d93167642b0008428fc

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * RangeUnitTest.cpp
10 *
11 * Created on: Nov 25, 2009
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include <cppunit/CompilerOutputter.h>
21#include <cppunit/extensions/TestFactoryRegistry.h>
22#include <cppunit/ui/text/TestRunner.h>
23
24#include "RangeUnitTest.hpp"
25
26#ifdef HAVE_TESTRUNNER
27#include "UnitTestMain.hpp"
28#endif /*HAVE_TESTRUNNER*/
29
30/********************************************** Test classes **************************************/
31
32// Registers the fixture into the 'registry'
33CPPUNIT_TEST_SUITE_REGISTRATION( RangeTest );
34
35
36void RangeTest::setUp()
37{
38 testrange = new range<int>(5,20);
39};
40
41
42void RangeTest::tearDown()
43{
44 delete testrange;
45};
46
47/** UnitTest for inRangeTest().
48 */
49void RangeTest::inRangeTest()
50{
51 // check valid range
52 for (int i=5; i<20; i++)
53 CPPUNIT_ASSERT(testrange->isInRange(i));
54
55 // check negative range
56 for (int i=-5; i>-20; i--)
57 CPPUNIT_ASSERT(!testrange->isInRange(i));
58
59 // lower limit-1 and upper limit are out of range
60 CPPUNIT_ASSERT(!testrange->isInRange(4));
61 CPPUNIT_ASSERT(!testrange->isInRange(20));
62
63 // isBefore
64 for (int i=4; i>=0; i--)
65 CPPUNIT_ASSERT(testrange->isBefore(i));
66
67 // isBeyond
68 for (int i=20; i<30; i++)
69 CPPUNIT_ASSERT(testrange->isBeyond(i));
70
71}
72
73/** UnitTest for operatorTest().
74 */
75void RangeTest::operatorTest()
76{
77 // check makeRange
78 range<int> true_comparison = makeRange(5,20);
79 range<int> false_comparison1 = makeRange(6,20);
80 range<int> false_comparison2 = makeRange(5,21);
81 range<int> false_comparison3 = makeRange(6,21);
82 CPPUNIT_ASSERT_EQUAL(testrange->first, true_comparison.first);
83 CPPUNIT_ASSERT_EQUAL(testrange->last, true_comparison.last);
84
85 // check operator==
86 CPPUNIT_ASSERT(*testrange == true_comparison);
87 // check operator!=
88 CPPUNIT_ASSERT(*testrange != false_comparison1);
89 CPPUNIT_ASSERT(*testrange != false_comparison2);
90 CPPUNIT_ASSERT(*testrange != false_comparison3);
91
92 // check operator<
93 CPPUNIT_ASSERT(!(*testrange < true_comparison));
94 CPPUNIT_ASSERT(*testrange < false_comparison1);
95 CPPUNIT_ASSERT(*testrange < false_comparison2);
96 CPPUNIT_ASSERT(*testrange < false_comparison3);
97 // check operator>
98 CPPUNIT_ASSERT(!(*testrange > true_comparison));
99 CPPUNIT_ASSERT(false_comparison1 > *testrange);
100 CPPUNIT_ASSERT(false_comparison2 > *testrange);
101 CPPUNIT_ASSERT(false_comparison3 > *testrange);
102 // check operator>=,<=
103 CPPUNIT_ASSERT(*testrange >= true_comparison);
104 CPPUNIT_ASSERT(*testrange <= true_comparison);
105}
Note: See TracBrowser for help on using the repository browser.