public void TestSuffixArrayWrongSize() { IBigArray <ulong> suffixArray = Program.convertIntArrayToBigUlongArray(new int[] { 1, 2, 3 }); FourBitDigitBigArray a = FourBitDigitBigArrayTests.convertStringTo4BitDigitArray("12345"); Assert.Throws <ArgumentException>(() => SearchString.Search(suffixArray, a, "23")); }
public void SearchSuffixArrayManualTest() { const string STR = "1234567899912340"; Dictionary <string, long[]> answers = new Dictionary <string, long[]>() { { "1", new long[] { 0, 11 } }, { "2", new long[] { 1, 12 } }, { "12", new long[] { 0, 11 } }, { "5", new long[] { 4 } } }; IBigArray <ulong> suffixArray = buildSuffixArray(STR); FourBitDigitBigArray fourBitDigitArray = FourBitDigitBigArrayTests.convertStringTo4BitDigitArray(STR); foreach (KeyValuePair <string, long[]> kvp in answers) { string find = kvp.Key; long[] expected = kvp.Value; SuffixArrayRange suffixArrayRange = SearchString.Search(suffixArray, fourBitDigitArray, find); long[] actual = suffixArrayRange.SortedValues; CollectionAssert.AreEqual(expected, actual); } }
public void SearchSuffixArrayForEmptyString() { const string STR = "123456789"; IBigArray <ulong> suffixArray = buildSuffixArray(STR); FourBitDigitBigArray fourBitDigitArray = FourBitDigitBigArrayTests.convertStringTo4BitDigitArray(STR); Assert.Throws <ArgumentException>(() => SearchString.Search(suffixArray, fourBitDigitArray, "")); }
public void TestDoesStartWithSuffixLastDigitsInDigitArray() { const string STR = "1234567890"; FourBitDigitBigArray fourBitDigitArray = FourBitDigitBigArrayTests.convertStringTo4BitDigitArray(STR); string strToFind = "90"; byte[] toFind = stringToByteArr(strToFind); Assert.AreEqual(0, SearchString.doesStartWithSuffix(fourBitDigitArray, toFind, STR.Length - 2)); }
public void TestDoesStartWithSuffixTooHigh() { const string STR = "12345678901234"; FourBitDigitBigArray fourBitDigitArray = FourBitDigitBigArrayTests.convertStringTo4BitDigitArray(STR); string strToFind = "2" + STR.Substring(1); byte[] toFind = stringToByteArr(strToFind); Assert.AreEqual(-1, SearchString.doesStartWithSuffix(fourBitDigitArray, toFind, 0)); }
public void SearchSuffixArrayAllDigits() { const string STR = "1234567899912340"; IBigArray <ulong> suffixArray = buildSuffixArray(STR); FourBitDigitBigArray fourBitDigitArray = FourBitDigitBigArrayTests.convertStringTo4BitDigitArray(STR); long[] expected = new long[] { 0 }; SuffixArrayRange suffixArrayRange = SearchString.Search(suffixArray, fourBitDigitArray, STR); long[] actual = suffixArrayRange.SortedValues; CollectionAssert.AreEqual(expected, actual); }
public void TestBinarySearchForPrefixSingleChars() { const string STR = "2734981324"; IBigArray <ulong> suffixArray = buildSuffixArray(STR); FourBitDigitBigArray fourBitDigitArray = FourBitDigitBigArrayTests.convertStringTo4BitDigitArray(STR); for (int i = 0; i < STR.Length; i++) { byte[] find = new byte[] { (byte)(STR[i] - '0') }; long answer = SearchString.binarySearchForPrefix(suffixArray, fourBitDigitArray, find, 0, STR.Length - 1); Assert.AreEqual(fourBitDigitArray[i], fourBitDigitArray[(long)suffixArray[answer]]); } }
public void SearchSuffixArraySearchEmptyString() { const string STR = ""; const string FIND = "1"; IBigArray <ulong> suffixArray = buildSuffixArray(STR); FourBitDigitBigArray fourBitDigitArray = FourBitDigitBigArrayTests.convertStringTo4BitDigitArray(STR); long[] expected = new long[0]; SuffixArrayRange suffixArrayRange = SearchString.Search(suffixArray, fourBitDigitArray, FIND); long[] actual = suffixArrayRange.SortedValues; CollectionAssert.AreEqual(expected, actual); }
public void TestSuffixArraySearchDigitNotInString() { const string STR = "1234567912340"; const string FIND = "8"; IBigArray <ulong> suffixArray = buildSuffixArray(STR); FourBitDigitBigArray fourBitDigitArray = FourBitDigitBigArrayTests.convertStringTo4BitDigitArray(STR); long[] expected = new long[] { }; SuffixArrayRange suffixArrayRange = SearchString.Search(suffixArray, fourBitDigitArray, FIND); long[] actual = suffixArrayRange.SortedValues; Assert.AreEqual(false, suffixArrayRange.HasResults); CollectionAssert.AreEqual(expected, actual); }
public void TestBinarySearchForPrefixDontExist() { const string STR = "8651287431284472619471"; IBigArray <ulong> suffixArray = buildSuffixArray(STR); FourBitDigitBigArray fourBitDigitArray = FourBitDigitBigArrayTests.convertStringTo4BitDigitArray(STR); string[] toFind = { "1234", "0", "0987654321", "5676", "10", "111", "33" }; foreach (string s in toFind) { byte[] find = stringToByteArr(s); long answer = SearchString.binarySearchForPrefix(suffixArray, fourBitDigitArray, find, 0, fourBitDigitArray.Length - 1); Assert.AreEqual(-1, answer); } }
public void TestDoesStartWithSuffixDigitArrayDigitArrayTooSmallNotMatchUntilEnd() { const string STR = "1234567890"; FourBitDigitBigArray fourBitDigitArray = FourBitDigitBigArrayTests.convertStringTo4BitDigitArray(STR); string strToFindHigh = "911"; byte[] toFindHigh = stringToByteArr(strToFindHigh); Assert.AreEqual(-1, SearchString.doesStartWithSuffix(fourBitDigitArray, toFindHigh, STR.Length - 2)); string strToFindLow = "871"; byte[] toFindLow = stringToByteArr(strToFindLow); Assert.AreEqual(1, SearchString.doesStartWithSuffix(fourBitDigitArray, toFindLow, STR.Length - 2)); }
public void TestDoesStartWithSuffix() { const string STR = "12345678901234"; FourBitDigitBigArray fourBitDigitArray = FourBitDigitBigArrayTests.convertStringTo4BitDigitArray(STR); //Start index for (int i = 0; i < STR.Length - 1; i++) { //End index for (int j = i + 1; j < STR.Length; j++) { string strFind = STR.Substring(i, j - i); byte[] find = stringToByteArr(strFind); Assert.AreEqual(0, SearchString.doesStartWithSuffix(fourBitDigitArray, find, i)); } } }
public void SearchSuffixArray() { const string STR = "123456789"; IBigArray <ulong> suffixArray = buildSuffixArray(STR); FourBitDigitBigArray fourBitDigitArray = FourBitDigitBigArrayTests.convertStringTo4BitDigitArray(STR); for (int i = 0; i < STR.Length; i++) { for (int j = i + 1; j <= STR.Length; j++) { string find = STR.Substring(i, j - i); long[] seqSearchRes = SearchString.Search(STR, find).ToLongArr(); SuffixArrayRange suffixArrayRange = SearchString.Search(suffixArray, fourBitDigitArray, find); long[] suffixArraySearchRes = suffixArrayRange.SortedValues; CollectionAssert.AreEqual(seqSearchRes, suffixArraySearchRes); } } }