示例#1
0
        public void Should_Check_Get_Set_Value()
        {
            //arrange
            int capacity = 5;
            var array    = new CircularArray <int>(capacity);

            //act
            array.SetValue(5, 0);
            array.SetValue(3, 1);
            array.SetValue(-3, 2);
            array.SetValue(4, 3);

            //assert
            ((int)array.GetValue(0)).ShouldBeEquivalentTo(5);
            ((int)array.GetValue(1)).ShouldBeEquivalentTo(3);
            ((int)array.GetValue(2)).ShouldBeEquivalentTo(-3);
            ((int)array.GetValue(3)).ShouldBeEquivalentTo(4);
            ((int)array.GetValue(4)).ShouldBeEquivalentTo(0);
            array.Count.ShouldBeEquivalentTo(capacity - 1);
        }
示例#2
0
        public void Should_Check_Set_Value_Throw_If_Invalid_Type()
        {
            //arrange
            int capacity = 5;
            var array    = new CircularArray <int>(capacity);

            //act
            array.SetValue(5, 0);
            array.SetValue(3, 1);
            Action act = () => array.SetValue("s", 2);

            array.SetValue(4, 3);

            //assert
            act.ShouldThrow <InvalidCastException>();

            ((int)array.GetValue(0)).ShouldBeEquivalentTo(5);
            ((int)array.GetValue(1)).ShouldBeEquivalentTo(3);
            ((int)array.GetValue(2)).ShouldBeEquivalentTo(0);
            ((int)array.GetValue(3)).ShouldBeEquivalentTo(4);
            ((int)array.GetValue(4)).ShouldBeEquivalentTo(0);
            array.Count.ShouldBeEquivalentTo(capacity - 2);
        }