Exemplo n.º 1
0
        public void WhenValueAndDepthOfTwoItemsAreUnequalTheyShouldYieldDifferentHashCodes()
        {
            var comparer = new DynamicComparer<Tuple<int, string>>( tuple => tuple.Item1.GetHashCode() );
            var command = new Command<string>( Console.WriteLine );
            var item1 = new HierarchicalItem<Tuple<int, string>>( new Tuple<int, string>( 2, "0" ), command, comparer );
            item1.Add( new HierarchicalItem<Tuple<int, string>>( new Tuple<int, string>( 1, "1" ), command, comparer ) );
            var item2 = new HierarchicalItem<Tuple<int, string>>( new Tuple<int, string>( 0, "2" ), command, comparer );
            item1[0].Add( item2 );

            Assert.NotEqual( item1.Depth, item2.Depth );
            Assert.NotEqual( item1.GetHashCode(), item2.GetHashCode() );
        }
Exemplo n.º 2
0
        public void TwoItemsWithTheSameValueAtDifferentDepthsShouldYieldDifferentHashCodes()
        {
            var comparer = new DynamicComparer<Tuple<int, string>>( tuple => tuple.Item1.GetHashCode() );
            var command = new Command<string>( Console.WriteLine );
            var item1 = new HierarchicalItem<Tuple<int, string>>( new Tuple<int, string>( 1, "0" ), command, comparer );
            item1.Add( new HierarchicalItem<Tuple<int, string>>( new Tuple<int, string>( 1, "1" ), command, comparer ) );
            var item2 = new HierarchicalItem<Tuple<int, string>>( new Tuple<int, string>( 1, "2" ), command, comparer );
            item1[0].Add( item2 );

            Assert.Equal( item1.Value.Item1, item2.Value.Item1 );
            Assert.NotEqual( item1.Depth, item2.Depth );
            Assert.NotEqual( item1.GetHashCode(), item2.GetHashCode() );
        }