From 250d6a4dbe61b6798cd090abeabdc0ece8237dd3 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sat, 25 Oct 2014 21:23:38 +0000 Subject: some restructuring, added first version of the mozjs plugin git-svn-id: file:///var/local/svn/basicwriter@78 daaaf23c-2e50-4459-9457-1e69db5a47bf --- test/core/utils/RangeSetTest.cpp | 222 +++++++++++++++++++++++++++++++++++++++ test/core/utils/Utils.cpp | 35 ------ test/core/utils/UtilsTest.cpp | 35 ++++++ 3 files changed, 257 insertions(+), 35 deletions(-) create mode 100644 test/core/utils/RangeSetTest.cpp delete mode 100644 test/core/utils/Utils.cpp create mode 100644 test/core/utils/UtilsTest.cpp (limited to 'test/core/utils') diff --git a/test/core/utils/RangeSetTest.cpp b/test/core/utils/RangeSetTest.cpp new file mode 100644 index 0000000..9be4c17 --- /dev/null +++ b/test/core/utils/RangeSetTest.cpp @@ -0,0 +1,222 @@ +/* + Ousía + Copyright (C) 2014 Benjamin Paaßen, Andreas Stöckel + + 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 3 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, see . +*/ + +#include + +#include + +namespace ousia { +namespace model { + +TEST(Range, IsValid) +{ + ASSERT_FALSE(Range().isValid()); + ASSERT_TRUE(Range(10).isValid()); + ASSERT_TRUE(Range(10, 20).isValid()); + ASSERT_FALSE(Range(20, 10).isValid()); +} + +TEST(Range, InRange) +{ + Range r(10, 20); + ASSERT_FALSE(r.inRange(0)); + ASSERT_FALSE(r.inRange(21)); + ASSERT_TRUE(r.inRange(10)); + ASSERT_TRUE(r.inRange(20)); + ASSERT_TRUE(r.inRange(15)); +} + +TEST(Range, overlaps) +{ + ASSERT_FALSE(Range(10, 20).overlaps(Range(0, 9))); + ASSERT_FALSE(Range(10, 20).overlaps(Range(21, 30))); + ASSERT_TRUE(Range(10, 20).overlaps(Range(0, 10))); + ASSERT_TRUE(Range(10, 20).overlaps(Range(20, 30))); + ASSERT_TRUE(Range(10, 20).overlaps(Range(5, 15))); + ASSERT_TRUE(Range(10, 20).overlaps(Range(15, 25))); + ASSERT_TRUE(Range(10, 20).overlaps(Range(15, 19))); + ASSERT_TRUE(Range(10, 20).overlaps(Range(15, 15))); + ASSERT_TRUE(Range(10, 20).overlaps(Range(10, 20))); + ASSERT_TRUE(Range(10, 20).overlaps(Range(0, 30))); +} + +TEST(Range, CoveredBy) +{ + ASSERT_FALSE(Range(10, 20).coveredBy(Range(0, 9))); + ASSERT_FALSE(Range(10, 20).coveredBy(Range(21, 30))); + ASSERT_FALSE(Range(10, 20).coveredBy(Range(0, 10))); + ASSERT_FALSE(Range(10, 20).coveredBy(Range(20, 30))); + ASSERT_FALSE(Range(10, 20).coveredBy(Range(5, 15))); + ASSERT_FALSE(Range(10, 20).coveredBy(Range(15, 25))); + ASSERT_FALSE(Range(10, 20).coveredBy(Range(15, 19))); + ASSERT_FALSE(Range(10, 20).coveredBy(Range(15, 15))); + ASSERT_TRUE(Range(10, 20).coveredBy(Range(10, 20))); + ASSERT_TRUE(Range(10, 20).coveredBy(Range(0, 30))); +} + +TEST(Range, Covers) +{ + ASSERT_FALSE(Range(10, 20).covers(Range(0, 9))); + ASSERT_FALSE(Range(10, 20).covers(Range(21, 30))); + ASSERT_FALSE(Range(10, 20).covers(Range(0, 10))); + ASSERT_FALSE(Range(10, 20).covers(Range(20, 30))); + ASSERT_FALSE(Range(10, 20).covers(Range(5, 15))); + ASSERT_FALSE(Range(10, 20).covers(Range(15, 25))); + ASSERT_TRUE(Range(10, 20).covers(Range(15, 19))); + ASSERT_TRUE(Range(10, 20).covers(Range(15, 15))); + ASSERT_TRUE(Range(10, 20).covers(Range(10, 20))); + ASSERT_FALSE(Range(10, 20).covers(Range(0, 30))); +} + +TEST(RangeSet, Neighbours) +{ + ASSERT_TRUE(Range(10, 19).neighbours(Range(20, 30))); + ASSERT_TRUE(Range(20, 29).neighbours(Range(10, 19))); +} + +TEST(Range, Merge) +{ + Range r1(10, 20); + Range r2(15, 25); + Range r3(5, 15); + Range rM = r1.merge(r2).merge(r3); + ASSERT_EQ(rM.start, 5); + ASSERT_EQ(rM.end, 25); +} + +TEST(RangeSet, Merge) +{ + RangeSet s; + auto &ranges = s.getRanges(); + + // Insert some non-overlapping elements into the range. We expect these to + // be just inserted into the ranges. + s.merge(Range( 0, 10)); + s.merge(Range(20, 30)); + s.merge(Range(40, 50)); + s.merge(Range(60, 70)); + { + ASSERT_EQ(ranges.size(), 4); + + auto it = ranges.begin(); + ASSERT_EQ((*it).start, 0); + ASSERT_EQ((*it).end, 10); + + it++; + ASSERT_EQ((*it).start, 20); + ASSERT_EQ((*it).end, 30); + + it++; + ASSERT_EQ((*it).start, 40); + ASSERT_EQ((*it).end, 50); + + it++; + ASSERT_EQ((*it).start, 60); + ASSERT_EQ((*it).end, 70); + } + + // Now insert an element which spans the second and third element + s.merge(Range(15, 55)); + { + ASSERT_EQ(ranges.size(), 3); + + auto it = ranges.begin(); + ASSERT_EQ((*it).start, 0); + ASSERT_EQ((*it).end, 10); + + it++; + ASSERT_EQ((*it).start, 15); + ASSERT_EQ((*it).end, 55); + + it++; + ASSERT_EQ((*it).start, 60); + ASSERT_EQ((*it).end, 70); + } + + // Now insert an element which expands the first element + s.merge(Range(-10, 11)); + { + ASSERT_EQ(ranges.size(), 3); + + auto it = ranges.begin(); + ASSERT_EQ((*it).start, -10); + ASSERT_EQ((*it).end, 11); + + it++; + ASSERT_EQ((*it).start, 15); + ASSERT_EQ((*it).end, 55); + + it++; + ASSERT_EQ((*it).start, 60); + ASSERT_EQ((*it).end, 70); + } + + // Now insert an element which merges the last two elements + s.merge(Range(13, 70)); + { + ASSERT_EQ(ranges.size(), 2); + + auto it = ranges.begin(); + ASSERT_EQ((*it).start, -10); + ASSERT_EQ((*it).end, 11); + + it++; + ASSERT_EQ((*it).start, 13); + ASSERT_EQ((*it).end, 70); + } + + // Now insert an element which merges the remaining elements + s.merge(Range(-9, 12)); + { + ASSERT_EQ(ranges.size(), 1); + + auto it = ranges.begin(); + ASSERT_EQ((*it).start, -10); + ASSERT_EQ((*it).end, 70); + } + +} + +TEST(RangeSet, Contains) +{ + RangeSet s; + + // Insert some non-overlapping elements into the range. We expect these to + // be just inserted into the ranges. + s.merge(Range( 0, 10)); + s.merge(Range(20, 30)); + s.merge(Range(40, 50)); + s.merge(Range(60, 70)); + s.merge(Range(71)); + s.merge(Range(72)); + s.merge(Range(73)); + s.merge(Range(74)); + + ASSERT_TRUE(s.contains(60)); + ASSERT_TRUE(s.contains(0)); + ASSERT_TRUE(s.contains(25)); + ASSERT_TRUE(s.contains(73)); + ASSERT_TRUE(s.contains(Range(25, 30))); + ASSERT_FALSE(s.contains(Range(25, 35))); + ASSERT_TRUE(s.contains(Range(0, 10))); + ASSERT_TRUE(s.contains(Range(70, 74))); +} + +} +} + diff --git a/test/core/utils/Utils.cpp b/test/core/utils/Utils.cpp deleted file mode 100644 index d349c6f..0000000 --- a/test/core/utils/Utils.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - Ousía - Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel - - 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 3 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, see . -*/ - -#include - -#include - -namespace ousia { - -TEST(Utils, isIdentifier) -{ - ASSERT_TRUE(Utils::isIdentifier("test")); - ASSERT_TRUE(Utils::isIdentifier("t0-_est")); - ASSERT_TRUE(Utils::isIdentifier("_t0-_EST")); - ASSERT_FALSE(Utils::isIdentifier("-t0-_EST")); - ASSERT_FALSE(Utils::isIdentifier("0t-_EST")); -} - -} - diff --git a/test/core/utils/UtilsTest.cpp b/test/core/utils/UtilsTest.cpp new file mode 100644 index 0000000..d349c6f --- /dev/null +++ b/test/core/utils/UtilsTest.cpp @@ -0,0 +1,35 @@ +/* + Ousía + Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel + + 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 3 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, see . +*/ + +#include + +#include + +namespace ousia { + +TEST(Utils, isIdentifier) +{ + ASSERT_TRUE(Utils::isIdentifier("test")); + ASSERT_TRUE(Utils::isIdentifier("t0-_est")); + ASSERT_TRUE(Utils::isIdentifier("_t0-_EST")); + ASSERT_FALSE(Utils::isIdentifier("-t0-_EST")); + ASSERT_FALSE(Utils::isIdentifier("0t-_EST")); +} + +} + -- cgit v1.2.3