public void VariableRepositoryTestClear()
        {
            IVariableRepository sut = new VariableRepository();
            var doubleReference     = sut.GetOrCreateVariable("AB", new short[] { 0, 0 });

            doubleReference.SetValue(new Accumulator(4.0));
            sut.Clear();
            var doubleReference2 = sut.GetOrCreateVariable("AB", new short[] { 0, 0 });

            Assert.AreEqual(0.0, doubleReference2.GetValue().ValueAsDouble());
        }
        public void VariableRepositoryDistinguishesArrayNamesToTwoCharacters()
        {
            IVariableRepository sut = new VariableRepository();
            var variableReference   = sut.GetOrCreateVariable("AB", new short[] { 2, 3 });
            var variableReference2  = sut.GetOrCreateVariable("AC", new short[] { 2, 3 });

            variableReference.SetValue(new Accumulator(4.0));
            var accumulator = variableReference2.GetValue();

            Assert.AreEqual(0.0, accumulator.GetValue(accumulator.Type));
            Assert.AreEqual(typeof(double), accumulator.Type);
        }
        public void VariableRepositoryTruncatesNamesToTwoCharacters()
        {
            IVariableRepository sut = new VariableRepository();
            var variableReference   = sut.GetOrCreateVariable("ABCD", new short[] { });

            variableReference.SetValue(new Accumulator(4.0));
            var variableReference2 = sut.GetOrCreateVariable("ABEF", new short[] { });
            var accumulator        = variableReference.GetValue();

            Assert.AreEqual(4.0, accumulator.GetValue(accumulator.Type));
            Assert.AreEqual(typeof(double), accumulator.Type);
        }
        public void VariableRepositoryDistinguishesStringArrayNamesToTwoCharacters()
        {
            IVariableRepository sut = new VariableRepository();
            var variableReference   = sut.GetOrCreateVariable("AB$", new short[] { 2, 3 });
            var variableReference2  = sut.GetOrCreateVariable("AC$", new short[] { 2, 3 });

            variableReference.SetValue(new Accumulator("HELLO"));
            var accumulator = variableReference2.GetValue();

            Assert.AreEqual(string.Empty, accumulator.GetValue(accumulator.Type));
            Assert.AreEqual(typeof(string), accumulator.Type);
        }
        public void VariableRepositoryTruncatesStringNamesToTwoCharacters()
        {
            IVariableRepository sut = new VariableRepository();
            var variableReference   = sut.GetOrCreateVariable("ABCD$", new short[] { });

            variableReference.SetValue(new Accumulator("HELLO"));
            var variableReference2 = sut.GetOrCreateVariable("ABEF$", new short[] { });
            var accumulator        = variableReference.GetValue();

            Assert.AreEqual("HELLO", accumulator.GetValue(accumulator.Type));
            Assert.AreEqual(typeof(string), accumulator.Type);
        }
        public void VariableRepositoryTruncatesShortArrayNamesToTwoCharacters()
        {
            IVariableRepository sut = new VariableRepository();
            var variableReference   = sut.GetOrCreateVariable("ABCD%", new short[] { 2, 3 });
            var variableReference2  = sut.GetOrCreateVariable("ABEF%", new short[] { 2, 3 });

            variableReference.SetValue(new Accumulator((short)4));
            var accumulator = variableReference2.GetValue();

            Assert.AreEqual((short)4, accumulator.GetValue(accumulator.Type));
            Assert.AreEqual(typeof(short), accumulator.Type);
        }
        public void VariableRepositoryReturnsEmptyStringOnFirstUse()
        {
            IVariableRepository sut = new VariableRepository();
            var variableReference   = sut.GetOrCreateVariable("N$", new short[] { });
            var accumulator         = variableReference.GetValue();

            Assert.AreEqual(string.Empty, accumulator.GetValue(accumulator.Type));
            Assert.AreEqual(typeof(string), accumulator.Type);
        }
        public void VariableRepositoryReturnsZeroShortOnFirstUse()
        {
            IVariableRepository sut = new VariableRepository();
            var variableReference   = sut.GetOrCreateVariable("N%", new short[] { });
            var accumulator         = variableReference.GetValue();

            Assert.AreEqual((short)0, accumulator.GetValue(accumulator.Type));
            Assert.AreEqual(typeof(short), accumulator.Type);
        }
        public void VariableRepositoryTestDefaultSize(short first, short second, bool shouldThrow)
        {
            IVariableRepository sut    = new VariableRepository();
            bool exceptionThrown       = false;
            var  doubleArrayReference  = sut.GetOrCreateVariable("AB", new short[] { 2, 3 });
            var  doubleArrayReference2 = sut.GetOrCreateVariable("AB", new short[] { first, second });

            try
            {
                doubleArrayReference2.SetValue(new Accumulator(2.0));
            }
            catch (ClassicBasic.Interpreter.Exceptions.BadSubscriptException)
            {
                exceptionThrown = true;
            }

            Assert.AreEqual(shouldThrow, exceptionThrown);
        }
        public void VariableRepositoryTypesAndArraysOccupyDifferentSpaces()
        {
            IVariableRepository sut  = new VariableRepository();
            var shortReference       = sut.GetOrCreateVariable("AB%", new short[] { });
            var doubleReference      = sut.GetOrCreateVariable("AB", new short[] { });
            var stringReference      = sut.GetOrCreateVariable("AB$", new short[] { });
            var shortArrayReference  = sut.GetOrCreateVariable("AB%", new short[] { 2, 3 });
            var doubleArrayReference = sut.GetOrCreateVariable("AB", new short[] { 2, 3 });
            var stringArrayReference = sut.GetOrCreateVariable("AB$", new short[] { 2, 3 });

            shortReference.SetValue(new Accumulator((short)1));
            shortArrayReference.SetValue(new Accumulator((short)2));
            stringReference.SetValue(new Accumulator("3"));
            stringArrayReference.SetValue(new Accumulator("4"));
            doubleReference.SetValue(new Accumulator(5.0));
            doubleArrayReference.SetValue(new Accumulator(6.0));

            var shortReference2       = sut.GetOrCreateVariable("AB%", new short[] { });
            var doubleReference2      = sut.GetOrCreateVariable("AB", new short[] { });
            var stringReference2      = sut.GetOrCreateVariable("AB$", new short[] { });
            var shortArrayReference2  = sut.GetOrCreateVariable("AB%", new short[] { 2, 3 });
            var doubleArrayReference2 = sut.GetOrCreateVariable("AB", new short[] { 2, 3 });
            var stringArrayReference2 = sut.GetOrCreateVariable("AB$", new short[] { 2, 3 });

            Assert.AreEqual((short)1, shortReference2.GetValue().GetValue(typeof(short)));
            Assert.AreEqual((short)2, shortArrayReference2.GetValue().GetValue(typeof(short)));
            Assert.AreEqual("3", stringReference2.GetValue().GetValue(typeof(string)));
            Assert.AreEqual("4", stringArrayReference2.GetValue().GetValue(typeof(string)));
            Assert.AreEqual(5.0, doubleReference2.GetValue().GetValue(typeof(double)));
            Assert.AreEqual(6.0, doubleArrayReference2.GetValue().GetValue(typeof(double)));
        }