aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/unit/testSparseVector.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2019-12-01 20:41:27 +1100
committerNeil <nyamatongwe@gmail.com>2019-12-01 20:41:27 +1100
commitda8c1844da6e593644f6ae056560553bb409b354 (patch)
tree201528b619cf13de885ae7b9a08acf3acdb5f7b0 /test/unit/testSparseVector.cxx
parent1e5534dde930d2b7eb2580f2c459d1553f3a5971 (diff)
downloadscintilla-mirror-da8c1844da6e593644f6ae056560553bb409b354.tar.gz
Allow setting value at end of a SparseVector.
Change representation of SparseVector in tests so last value can be seen.
Diffstat (limited to 'test/unit/testSparseVector.cxx')
-rw-r--r--test/unit/testSparseVector.cxx65
1 files changed, 45 insertions, 20 deletions
diff --git a/test/unit/testSparseVector.cxx b/test/unit/testSparseVector.cxx
index 7f2a9e9af..67b8a05f8 100644
--- a/test/unit/testSparseVector.cxx
+++ b/test/unit/testSparseVector.cxx
@@ -28,7 +28,7 @@ using namespace Scintilla;
// to simplify checks.
static std::string Representation(const SparseVector<UniqueString> &st) {
std::string ret;
- for (int i = 0;i < st.Length();i++) {
+ for (int i = 0;i <= st.Length();i++) {
const char *value = st.ValueAt(i).get();
if (value && *value)
ret += value;
@@ -45,6 +45,7 @@ TEST_CASE("SparseVector") {
SECTION("IsEmptyInitially") {
REQUIRE(1 == st.Elements());
REQUIRE(0 == st.Length());
+ REQUIRE("-" == Representation(st));
st.Check();
}
@@ -61,7 +62,7 @@ TEST_CASE("SparseVector") {
st.InsertSpace(0, 5);
st.SetValueAt(3, UniqueStringCopy("3"));
REQUIRE(2 == st.Elements());
- REQUIRE("---3-" == Representation(st));
+ REQUIRE("---3--" == Representation(st));
st.Check();
}
@@ -75,7 +76,7 @@ TEST_CASE("SparseVector") {
st.DeletePosition(3);
REQUIRE(1 == st.Elements());
REQUIRE(4 == st.Length());
- REQUIRE("----" == Representation(st));
+ REQUIRE("-----" == Representation(st));
st.Check();
}
@@ -84,7 +85,13 @@ TEST_CASE("SparseVector") {
st.InsertSpace(0, 5);
st.SetValueAt(0, UniqueStringCopy("3"));
REQUIRE(1 == st.Elements());
- REQUIRE("3----" == Representation(st));
+ REQUIRE("3-----" == Representation(st));
+ st.DeletePosition(0);
+ REQUIRE(1 == st.Elements());
+ REQUIRE("-----" == Representation(st));
+ st.SetValueAt(0, UniqueStringCopy("4"));
+ REQUIRE(1 == st.Elements());
+ REQUIRE("4----" == Representation(st));
st.DeletePosition(0);
REQUIRE(1 == st.Elements());
REQUIRE("----" == Representation(st));
@@ -102,10 +109,10 @@ TEST_CASE("SparseVector") {
st.InsertSpace(0, 5);
st.SetValueAt(0, UniqueStringCopy("3"));
REQUIRE(1 == st.Elements());
- REQUIRE("3----" == Representation(st));
+ REQUIRE("3-----" == Representation(st));
st.InsertSpace(0, 1);
REQUIRE(2 == st.Elements());
- REQUIRE("-3----" == Representation(st));
+ REQUIRE("-3-----" == Representation(st));
st.Check();
}
@@ -114,10 +121,10 @@ TEST_CASE("SparseVector") {
st.InsertSpace(0, 5);
st.SetValueAt(1, UniqueStringCopy("1"));
REQUIRE(2 == st.Elements());
- REQUIRE("-1---" == Representation(st));
+ REQUIRE("-1----" == Representation(st));
st.InsertSpace(1, 1);
REQUIRE(2 == st.Elements());
- REQUIRE("--1---" == Representation(st));
+ REQUIRE("--1----" == Representation(st));
st.Check();
}
@@ -126,10 +133,10 @@ TEST_CASE("SparseVector") {
st.InsertSpace(0, 5);
st.SetValueAt(1, UniqueStringCopy("9"));
REQUIRE(2 == st.Elements());
- REQUIRE("-9---" == Representation(st));
+ REQUIRE("-9----" == Representation(st));
st.InsertSpace(0, 1);
REQUIRE(2 == st.Elements());
- REQUIRE("--9---" == Representation(st));
+ REQUIRE("--9----" == Representation(st));
// Initial st has allocation of 9 values so this should cause reallocation
const std::string letters("ABCDEFGHIJKLMNOP"); // 16 letters
for (const char letter : letters) {
@@ -137,7 +144,7 @@ TEST_CASE("SparseVector") {
st.InsertSpace(0, 1);
st.SetValueAt(1, UniqueStringCopy(sLetter));
}
- REQUIRE("-PONMLKJIHGFEDCBA-9---" == Representation(st));
+ REQUIRE("-PONMLKJIHGFEDCBA-9----" == Representation(st));
st.Check();
}
@@ -146,10 +153,16 @@ TEST_CASE("SparseVector") {
st.InsertSpace(0, 5);
st.SetValueAt(4, UniqueStringCopy("5"));
REQUIRE(2 == st.Elements());
- REQUIRE("----5" == Representation(st));
+ REQUIRE("----5-" == Representation(st));
+ st.SetValueAt(5, UniqueStringCopy("6"));
+ REQUIRE(2 == st.Elements());
+ REQUIRE("----56" == Representation(st));
st.DeletePosition(4);
REQUIRE(1 == st.Elements());
- REQUIRE("----" == Representation(st));
+ REQUIRE("----6" == Representation(st));
+ st.SetValueAt(4, UniqueStringCopy("7"));
+ REQUIRE(1 == st.Elements());
+ REQUIRE("----7" == Representation(st));
st.Check();
}
@@ -158,10 +171,10 @@ TEST_CASE("SparseVector") {
st.InsertSpace(0, 5);
st.SetValueAt(4, UniqueStringCopy("5"));
REQUIRE(2 == st.Elements());
- REQUIRE("----5" == Representation(st));
+ REQUIRE("----5-" == Representation(st));
st.SetValueAt(4, nullptr);
REQUIRE(1 == st.Elements());
- REQUIRE("-----" == Representation(st));
+ REQUIRE("------" == Representation(st));
st.Check();
}
@@ -169,16 +182,16 @@ TEST_CASE("SparseVector") {
REQUIRE(1 == st.Elements());
st.InsertSpace(0, 1);
st.SetValueAt(0, UniqueStringCopy("1"));
- REQUIRE("1" == Representation(st));
+ REQUIRE("1-" == Representation(st));
REQUIRE(1 == st.Elements());
st.InsertSpace(1, 1);
st.SetValueAt(1, UniqueStringCopy("2"));
- REQUIRE("12" == Representation(st));
+ REQUIRE("12-" == Representation(st));
st.DeletePosition(0);
- REQUIRE("2" == Representation(st));
+ REQUIRE("2-" == Representation(st));
REQUIRE(1 == st.Elements());
st.DeletePosition(0);
- REQUIRE("" == Representation(st));
+ REQUIRE("-" == Representation(st));
}
SECTION("DeleteAll") {
@@ -189,10 +202,22 @@ TEST_CASE("SparseVector") {
st.SetValueAt(4, UniqueStringCopy("4"));
st.SetValueAt(3, UniqueStringCopy("3"));
REQUIRE(5 == st.Elements());
- REQUIRE("---34--7-9" == Representation(st));
+ REQUIRE("---34--7-9-" == Representation(st));
st.Check();
}
+ SECTION("DeleteStarting") {
+ REQUIRE(1 == st.Elements());
+ st.InsertSpace(0, 2);
+ st.SetValueAt(0, UniqueStringCopy("1"));
+ st.SetValueAt(1, UniqueStringCopy("2"));
+ REQUIRE("12-" == Representation(st));
+ st.DeletePosition(0);
+ REQUIRE("2-" == Representation(st));
+ st.DeletePosition(0);
+ REQUIRE("-" == Representation(st));
+ }
+
}
TEST_CASE("SparseTextInt") {