Exemple #1
0
        static void Main(string[] args)
        {
            var stringComp = new StringComparator();

            var result = stringComp.BackspaceCompare("a##c",
                                                     "#a#c");
        }
Exemple #2
0
        public void ExistenceOfStringTreeTest()
        {
            InterfaceOfComparator <string> comparator = new StringComparator();
            BinaryTree <string>            tree       = new BinaryTree <string>(comparator);

            Assert.IsTrue(tree.IsEmpty());
        }
 public void StringArrayTest()
 {
     string[] array = new string[] { "toa", "rrra", "fdaswf"};
     StringComparator stringComparator = new StringComparator();
     BubbleSort.BubbleSorting<string>(array, 3, stringComparator);
     Assert.IsTrue(array[0] == "fdaswf" && array[1] == "rrra" && array[2] == "toa");
 }
Exemple #4
0
        public void IsElementExistInStringTreeTest()
        {
            InterfaceOfComparator <string> comparator = new StringComparator();
            BinaryTree <string>            tree       = new BinaryTree <string>(comparator);

            tree.InsertElement("ololo");
            Assert.IsTrue(tree.IsElementExist("ololo"));
        }
Exemple #5
0
        public void InsertToStringTreeTest()
        {
            InterfaceOfComparator <string> comparator = new StringComparator();
            BinaryTree <string>            tree       = new BinaryTree <string>(comparator);

            tree.InsertElement("ololo");
            Assert.IsFalse(tree.IsEmpty());
        }
Exemple #6
0
        public void Should_be_possible_to_compare_two_strings_using_case_insensitive_not_equals()
        {
            StringComparator comparator = new StringComparator();

            bool compareResult = comparator.Compare("risk managerng", "risk managerNG", OperationEnumeration.caseinsensitivenotequal);

            Assert.IsFalse(compareResult, "the result of comparator is not expected");

            compareResult = comparator.Compare(@"SOFTWARE\Modulo", @"Software\Modulo", OperationEnumeration.caseinsensitivenotequal);
            Assert.IsFalse(compareResult, "the result of comparator is not expected");
        }
Exemple #7
0
        public void Should_be_possible_to_compare_two_strings_using_equals_operator()
        {
            StringComparator comparator = new StringComparator();

            bool compareResult = comparator.Compare("risk manager", "risk manager", OperationEnumeration.equals);

            Assert.IsTrue(compareResult, "the result of comparator is not expected");

            compareResult = comparator.Compare("40", "41", OperationEnumeration.equals);
            Assert.IsFalse(compareResult, "the result of comparator is not expected");
        }
Exemple #8
0
        public void Should_be_possible_to_compare_two_strings_using_equals_operator_with_case_sensitive_form()
        {
            StringComparator comparator = new StringComparator();

            bool compareResult = comparator.Compare(@"SOFTWARE\Modulo", @"SOFTWARE\Modulo", OperationEnumeration.equals);

            Assert.IsTrue(compareResult, "the result of comparator is not expected");

            compareResult = comparator.Compare(@"SOFTWARE\Modulo", @"Software\Modulo", OperationEnumeration.equals);
            Assert.IsFalse(compareResult, "the result of comparator is not expected");

            compareResult = comparator.Compare(@"SOFTWARE\MoDulo", @"SOFTWARE\Modulo", OperationEnumeration.equals);
            Assert.IsFalse(compareResult, "the result of comparator is not expected");
        }
Exemple #9
0
        public void RemoveFromRootTest()
        {
            InterfaceOfComparator <string> comparator = new StringComparator();
            BinaryTree <string>            tree       = new BinaryTree <string>(comparator);

            tree.InsertElement("3");
            tree.InsertElement("1");
            tree.InsertElement("5");
            tree.RemoveElement("3");

            Assert.IsTrue(tree.IsElementExist("1"));
            Assert.IsTrue(tree.IsElementExist("5"));
            Assert.IsFalse(tree.IsElementExist("3"));
        }
Exemple #10
0
        public void Should_be_possible_to_compare_a_string_against_regex_pattern()
        {
            StringComparator comparator = new StringComparator();

            bool compareResult = comparator.Compare("Version", "V.*", OperationEnumeration.patternmatch);

            Assert.IsTrue(compareResult, "the result of comparator is no expected for pattern match operation");

            compareResult = comparator.Compare("Direct", "^Direct.*", OperationEnumeration.patternmatch);
            Assert.IsTrue(compareResult, "the result of comparator is no expected for pattern match operation");

            compareResult = comparator.Compare("Direct Version", "^Direct.*", OperationEnumeration.patternmatch);
            Assert.IsTrue(compareResult, "the result of comparator is no expected for pattern match operation");
        }
Exemple #11
0
        public void Delete_TryDeleteNoExistElement_Exception()
        {
            var comparer = new StringComparator();

            var map = new RbTree <string, int>(comparer);

            map.Insert("kgj", 45);

            map.Insert("a", 21);

            map.Insert("vba", 90);

            Assert.Throws <Exception>(() => map.Delete("b"));
        }
Exemple #12
0
        public void EnumeratorStringTest()
        {
            InterfaceOfComparator <string> comparator = new StringComparator();
            BinaryTree <string>            tree       = new BinaryTree <string>(comparator);

            tree.InsertElement("ololo");
            tree.InsertElement("trololo");
            string elements = "";

            foreach (string i in tree)
            {
                elements += i + "  ";
            }
            Assert.AreEqual("trololo  ololo  ", elements);
        }
Exemple #13
0
        public void Find_TryFindNoExistElement_Exception()
        {
            var comparer = new StringComparator();

            var map = new RbTree <string, int>(comparer);

            map.Insert("ffg", 45);

            map.Insert("acb", 21);

            map.Insert("hyred", 90);

            map.Delete("acb");

            Assert.Throws <Exception>(() => map.Find("acb"));
        }
Exemple #14
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            PropertyInfo propertyInfo = validationContext.ObjectType.GetProperty(_comparePropertyName);

            if (propertyInfo == null)
            {
                return(null);
            }

            if (value == null)
            {
                return(null);
            }

            if (!propertyInfo.PropertyType.Equals(value.GetType()))
            {
                return(null);
            }

            bool result = false;

            switch (_compareType)
            {
            case CompareType.NUMBER:
                result = new NumberComparator().Compare((float)value, (float)propertyInfo.GetValue(validationContext.ObjectInstance), _compareOperator);
                break;

            case CompareType.TIME:
                result = new TimeComparator().Compare((string)value, (string)propertyInfo.GetValue(validationContext.ObjectInstance), _compareOperator);
                break;

            case CompareType.DATE:
                result = new DateComparator().Compare((DateTime)value, (DateTime)propertyInfo.GetValue(validationContext.ObjectInstance), _compareOperator);
                break;

            case CompareType.STRING:
                result = new StringComparator().Compare((string)value, (string)propertyInfo.GetValue(validationContext.ObjectInstance), _compareOperator);
                break;
            }

            if (!result)
            {
                return(new ValidationResult(string.Format(ErrorMessageString, validationContext.DisplayName, _comparePropertyName)));
            }

            return(ValidationResult.Success);
        }
Exemple #15
0
        private bool AreEqual <T>(IReadOnlyList <T> list1, IReadOnlyList <T> list2, StringComparator comparer)
        {
            if (list1.Count != list2.Count)
            {
                return(false);
            }

            for (int i = 0; i < list1.Count; i++)
            {
                if (comparer.compare(list1[i], list2[i]) != 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #16
0
        public void Print_InsertThreeElements_CorrectPrint()
        {
            var comparer = new StringComparator();

            var map = new RbTree <string, int>(comparer);

            map.Insert("tt", 145);

            map.Insert("bb", 323);

            map.Insert("gg", 476);

            var actualOutput = map.ToString();

            var expectedOutput = "key = bb value = 323\nkey = gg value = 476\nkey = tt value = 145\n";

            Assert.AreEqual(expectedOutput, actualOutput);
        }
Exemple #17
0
        public void Insert_InsertThreeElements_CorrectInsert()
        {
            var comparer = new StringComparator();

            var map = new RbTree <string, int>(comparer);

            map.Insert("dog", 44);

            map.Insert("cat", 63);

            map.Insert("sun", 81);

            var actualCount = map.Count;

            var expectedCount = 3;

            Assert.AreEqual(expectedCount, actualCount);
        }
Exemple #18
0
        public void Clear_InsertTwoElementsAndClear_EmptyMap()
        {
            var comparer = new StringComparator();

            var map = new RbTree <string, int>(comparer);

            map.Insert("me", 55);

            map.Insert("you", 43);

            map.Clear();

            var actualCount = map.Count;

            var expectedCount = 0;

            Assert.AreEqual(expectedCount, actualCount);
        }
Exemple #19
0
        public void GetValues_InsertThreeElements_GetTheeValues()
        {
            var comparer = new StringComparator();

            var map = new RbTree <string, int>(comparer);

            map.Insert("Fgd", 453);

            map.Insert("ddd", 123);

            map.Insert("czh", 532);

            var actualValues = map.GetValues();

            var expectedValues = new List <int> {
                532, 123, 453
            };

            Assert.IsTrue(IsEqual(actualValues, expectedValues));
        }
Exemple #20
0
        public void GetKeys_InsertThreeElements_GetThreeKeys()
        {
            var comparer = new StringComparator();

            var map = new RbTree <string, int>(comparer);

            map.Insert("ss", 55);

            map.Insert("aaa", -723);

            map.Insert("zzz", 797);

            var actualKeys = map.GetKeys();

            var expectedKeys = new List <string> {
                "aaa", "ss", "zzz"
            };

            Assert.IsTrue(AreEqual(expectedKeys, actualKeys, comparer));
        }
Exemple #21
0
        /// @param firstString
        ///     The string to check
        /// @param otherString
        ///     The string to compare with
        /// @param comparator
        ///     The method of comparison to use
        ///
        /// @return Whether the strings are matching the comparison criterion
        ///
        public static bool Matches(this string firstString, string otherString, StringComparator comparator = StringComparator.Identical)
        {
            bool match = false;

            switch (comparator)
            {
            case StringComparator.Identical:
            {
                match = (firstString == otherString);
                break;
            }

            case StringComparator.Contains:
            {
                match = firstString.Contains(otherString);
                break;
            }

            case StringComparator.StartsWith:
            {
                match = firstString.StartsWith(otherString);
                break;
            }

            case StringComparator.EndsWith:
            {
                match = firstString.EndsWith(otherString);
                break;
            }

            default:
            {
                Debug.LogError(string.Format("Unknown comparator '{0}'. Could not compare '{1}' and '{2}'", comparator.ToString(), firstString, otherString));
                break;
            }
            }

            return(match);
        }
Exemple #22
0
        public void Delete_InsertThreeElementsAndDeleteTwoElements_FindOneElement()
        {
            var comparer = new StringComparator();

            var map = new RbTree <string, int>(comparer);

            map.Insert("vga", 5);

            map.Insert("hj", 1);

            map.Insert("vbz", 9);

            map.Delete("vga");

            map.Delete("vbz");

            var actual = map.Find("hj");

            var expected = 1;

            Assert.AreEqual(expected, actual);
        }
Exemple #23
0
        public void Find_InsertFiveElements_CorrectValue()
        {
            var comparer = new StringComparator();

            var map = new RbTree <string, int>(comparer);

            map.Insert("Me", 51);

            map.Insert("You", 651);

            map.Insert("Her", 89);

            map.Insert("Him", 612);

            map.Insert("zero", -7);

            var actual = map.Find("Him");

            var expected = 612;

            Assert.AreEqual(expected, actual);
        }
Exemple #24
0
        public void Delete_InsertSevenElementsAndDeleteFourElements_FindAllElement()
        {
            var comparer = new StringComparator();

            var map = new RbTree <string, int>(comparer);

            map.Insert("aa", 5);

            map.Insert("ab", 1);

            map.Insert("zzz", 9);

            map.Insert("4ga", 189);

            map.Insert("11", 22);

            map.Insert("bn", 56);

            map.Insert("az", 88);

            map.Delete("aa");

            map.Delete("ab");

            map.Delete("zzz");

            map.Delete("bn");

            var actual = map.GetKeys();

            var expected = new List <string> {
                "11", "4ga", "az"
            };

            Assert.IsTrue(AreEqual(actual, expected, comparer));
        }