/***********************************************************************//** * @brief Test GGti ***************************************************************************/ void TestGObservation::test_gti(void) { // Test void constructor test_try("Void constructor"); try { GGti gti; test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Manipulate GTIs starting from an empty object GGti gti; test_value(gti.size(), 0, "GGti should have zero size."); test_assert(gti.is_empty(), "GGti should be empty."); test_value(gti.tstart().secs(), 0.0, 1.0e-10, "Start time should be 0."); test_value(gti.tstop().secs(), 0.0, 1.0e-10, "Stop time should be 0."); // Add empty interval gti.append(GTime(1.0), GTime(1.0)); test_value(gti.size(), 0, "GGti should have zero size."); test_assert(gti.is_empty(), "GGti should be empty."); test_value(gti.tstart().secs(), 0.0, 1.0e-10, "Start time should be 0."); test_value(gti.tstop().secs(), 0.0, 1.0e-10, "Stop time should be 0."); // Add one interval gti.append(GTime(1.0), GTime(10.0)); test_value(gti.size(), 1, "GGti should have 1 interval."); test_assert(!gti.is_empty(), "GGti should not be empty."); test_value(gti.tstart().secs(), 1.0, 1.0e-10, "Start time should be 1."); test_value(gti.tstop().secs(), 10.0, 1.0e-10, "Stop time should be 10."); // Remove interval gti.remove(0); test_value(gti.size(), 0, "GGti should have zero size."); test_assert(gti.is_empty(), "GGti should be empty."); test_value(gti.tstart().secs(), 0.0, 1.0e-10, "Start time should be 0."); test_value(gti.tstop().secs(), 0.0, 1.0e-10, "Stop time should be 0."); // Append two overlapping intervals gti.append(GTime(1.0), GTime(100.0)); gti.append(GTime(10.0), GTime(1000.0)); test_value(gti.size(), 2, "GGti should have 2 intervals."); test_assert(!gti.is_empty(), "GGti should not be empty."); test_value(gti.tstart().secs(), 1.0, 1.0e-10, "Start time should be 1."); test_value(gti.tstop().secs(), 1000.0, 1.0e-10, "Stop time should be 1000."); // Clear object gti.clear(); test_value(gti.size(), 0, "GGti should have zero size."); test_assert(gti.is_empty(), "GGti should be empty."); test_value(gti.tstart().secs(), 0.0, 1.0e-10, "Start time should be 0."); test_value(gti.tstop().secs(), 0.0, 1.0e-10, "Stop time should be 0."); // Append two overlapping intervals in inverse order gti.clear(); gti.append(GTime(10.0), GTime(1000.0)); gti.append(GTime(1.0), GTime(100.0)); test_value(gti.size(), 2, "GGti should have 2 intervals."); test_assert(!gti.is_empty(), "GGti should not be empty."); test_value(gti.tstart().secs(), 1.0, 1.0e-10, "Start time should be 1."); test_value(gti.tstop().secs(), 1000.0, 1.0e-10, "Stop time should be 1000."); // Insert two overlapping intervals gti.clear(); gti.insert(GTime(1.0), GTime(100.0)); gti.insert(GTime(10.0), GTime(1000.0)); test_value(gti.size(), 2, "GGti should have 2 intervals."); test_assert(!gti.is_empty(), "GGti should not be empty."); test_value(gti.tstart().secs(), 1.0, 1.0e-10, "Start time should be 1."); test_value(gti.tstop().secs(), 1000.0, 1.0e-10, "Stop time should be 1000."); // Insert two overlapping intervals in inverse order gti.clear(); gti.insert(GTime(10.0), GTime(1000.0)); gti.insert(GTime(1.0), GTime(100.0)); test_value(gti.size(), 2, "GGti should have 2 intervals."); test_assert(!gti.is_empty(), "GGti should not be empty."); test_value(gti.tstart().secs(), 1.0, 1.0e-10, "Start time should be 1."); test_value(gti.tstop().secs(), 1000.0, 1.0e-10, "Stop time should be 1000."); // Merge two overlapping intervals gti.clear(); gti.merge(GTime(1.0), GTime(100.0)); gti.merge(GTime(10.0), GTime(1000.0)); test_value(gti.size(), 1, "GGti should have 1 interval."); test_assert(!gti.is_empty(), "GGti should not be empty."); test_value(gti.tstart().secs(), 1.0, 1.0e-10, "Start time should be 1."); test_value(gti.tstop().secs(), 1000.0, 1.0e-10, "Stop time should be 1000."); // Merge two overlapping intervals in inverse order gti.clear(); gti.merge(GTime(10.0), GTime(1000.0)); gti.merge(GTime(1.0), GTime(100.0)); test_value(gti.size(), 1, "GGti should have 1 interval."); test_assert(!gti.is_empty(), "GGti should not be empty."); test_value(gti.tstart().secs(), 1.0, 1.0e-10, "Start time should be 1."); test_value(gti.tstop().secs(), 1000.0, 1.0e-10, "Stop time should be 1000."); // Check extension gti.clear(); gti.append(GTime(1.0), GTime(10.0)); gti.append(GTime(10.0), GTime(100.0)); GGti ext; ext.append(GTime(100.0), GTime(1000.0)); gti.extend(ext); test_value(gti.size(), 3, "GGti should have 3 intervals."); test_assert(!gti.is_empty(), "GGti should not be empty."); test_value(gti.tstart(0).secs(), 1.0, 1.0e-10, "Bin 0 start time should be 1."); test_value(gti.tstart(1).secs(), 10.0, 1.0e-10, "Bin 1 start time should be 10."); test_value(gti.tstart(2).secs(), 100.0, 1.0e-10, "Bin 2 start time should be 100."); test_value(gti.tstop(0).secs(), 10.0, 1.0e-10, "Bin 0 stop time should be 10."); test_value(gti.tstop(1).secs(), 100.0, 1.0e-10, "Bin 1 stop time should be 100."); test_value(gti.tstop(2).secs(), 1000.0, 1.0e-10, "Bin 2 stop time should be 1000."); test_value(gti.tstart().secs(), 1.0, 1.0e-10, "Start time should be 1."); test_value(gti.tstop().secs(), 1000.0, 1.0e-10, "Stop time should be 1000."); // Return return; }