コード例 #1
0
        public void TestCompares(string x, string y, int expectedResult)
        {
            var comparer = new PrefixStringComparer();

            var result = comparer.Compare(x, y);

            result.Should().Be(expectedResult);
        }
コード例 #2
0
        public void Throw_ArgumentException_If_Passed_Values_Is_Null(string x, string y)
        {
            var comparer = new PrefixStringComparer();

            Action compareAction = () => comparer.Compare(x, y);

            compareAction.Should().Throw <ArgumentException>().And.Message.Should().Be("Passed string could not be null");
        }
コード例 #3
0
        public void Can_Get_Range_Value_By_Prefix_Comparer()
        {
            var stringComparer = StringComparer.Ordinal;
            var prefixComparer = new PrefixStringComparer();
            var suffixArray    = new SuffixArray <string, int>();

            int[] value;

            suffixArray.TryAdd("_test", 1, stringComparer);
            suffixArray.TryAdd("_est", 2, stringComparer);
            suffixArray.TryAdd("test", 3, stringComparer);
            suffixArray.TryAdd("zone", 4, stringComparer);
            suffixArray.TryAdd("z", 5, stringComparer);

            suffixArray.TryGetRangeValue("_", out value, prefixComparer).Should().BeTrue();
            value.Should().BeEquivalentTo(1, 2);
            suffixArray.TryGetRangeValue("z", out value, prefixComparer).Should().BeTrue();
            value.Should().BeEquivalentTo(4, 5);
            suffixArray.TryGetRangeValue("not_exists", out value, prefixComparer).Should().BeFalse();
        }