Exemplo n.º 1
0
 public void TestNullObject()
 {
     //2 null object, equal
     VariableLine variableLine1 = new VariableLine();
     VariableLine variableLine2 = new VariableLine();
     Assert.AreEqual(variableLine1, variableLine2);
 }
Exemplo n.º 2
0
 public void TestInsertToDict()
 {
     Assert.Throws<ArgumentException>(() =>
     {
         Dictionary<VariableLine, int> dictionary = new Dictionary<VariableLine, int>();
         VariableLine vL = new VariableLine("variable", 213);
         dictionary.Add(vL, 1);
         dictionary.Add(vL, 2);
     });
     Assert.Throws<ArgumentException>(() =>
     {
         Dictionary<VariableLine, int> dictionary = new Dictionary<VariableLine, int>();
         VariableLine vL = new VariableLine("variable", 213);
         dictionary.Add(vL, 1);
         dictionary.Add(vL, 1);
     });
     Assert.Throws<NullReferenceException>(() =>
     {
         Dictionary<VariableLine, int> dictionary = new Dictionary<VariableLine, int>();
         VariableLine vL = new VariableLine("variable", 213);
         VariableLine vL2 = new VariableLine();
         dictionary.Add(vL, 1);
         dictionary.Add(vL2, 1);
     });
 }
Exemplo n.º 3
0
 public void TestNegativeLine()
 {
     Assert.Throws<ArgumentException>(() =>
     {
         VariableLine v = new VariableLine("variable", -100);
     });
     Assert.Throws<ArgumentException>(() =>
     {
         VariableLine v = new VariableLine("", 100);
     });
 }
Exemplo n.º 4
0
 public void TestDiffNameLine()
 {
     //diff name, diff line, not equal
     VariableLine variableLine1 = new VariableLine("variable1", 123312);
     VariableLine variableLine2 = new VariableLine("variable2", 68678);
     Assert.AreNotEqual(variableLine1, variableLine2);
 }
Exemplo n.º 5
0
 public void TestEqual()
 {
     //same name, same line, equal
     VariableLine variableLine1 = new VariableLine("variable1", 123312);
     VariableLine variableLine2 = new VariableLine("variable1", 123312);
     Assert.AreEqual(variableLine1, variableLine2);
 }
Exemplo n.º 6
0
 public void TestCapitalLetter()
 {
     //diff name, same line not equal
     VariableLine variableLine1 = new VariableLine("VARIablE", 123312);
     VariableLine variableLine2 = new VariableLine("variable1", 123312);
     Assert.AreNotEqual(variableLine1, variableLine2);
     //same name, same line, equal
     variableLine1 = new VariableLine("VARIablE", 123312);
     variableLine2 = new VariableLine("VARIablE", 123312);
     Assert.AreEqual(variableLine1, variableLine2);
     //same name, diff line, not equal
     variableLine1 = new VariableLine("VARIablE", 123312);
     variableLine2 = new VariableLine("VARIablE", 68678);
     Assert.AreNotEqual(variableLine1, variableLine2);
 }
Exemplo n.º 7
0
 public void Test1NullObject()
 {
     //1 null object, not equal
     VariableLine variableLine1 = new VariableLine("variable1", 123312);
     VariableLine variableLine2 = new VariableLine();
     Assert.AreNotEqual(variableLine1, variableLine2);
 }
Exemplo n.º 8
0
        private List<VariableLine> FormatNewOutputLinesFromHashSet(HashSet<VariableLine> hashSet)
        {
            if (hashSet == null)
                throw new ArgumentNullException("hashSet");

            List<VariableLine> list = new List<VariableLine>();
            foreach (VariableLine variableLine in hashSet)
            {
                VariableLine newVariableLine = new VariableLine(variableLine.variable, variableLine.line - 1);
                list.Add(newVariableLine);
            }
            return list;
        }
Exemplo n.º 9
0
        private Dictionary<int, List<VariableLine>> FormatNewInputLinesFromDicitionary(Dictionary<int, List<VariableLine>> dictionary)
        {
            if (dictionary == null)
                throw new ArgumentNullException("dictionary");

            Dictionary<int, List<VariableLine>> newDicitionary = new Dictionary<int, List<VariableLine>>();
            foreach (KeyValuePair<int, List<VariableLine>> kvp in dictionary)
            {
                List<VariableLine> list = new List<VariableLine>();
                foreach (VariableLine variableLine in kvp.Value)
                {
                    VariableLine newVariableLine = new VariableLine(variableLine.variable, variableLine.line - 1);
                    list.Add(newVariableLine);
                }
                newDicitionary.Add(kvp.Key - 1, list);
            }
            return newDicitionary;
        }
Exemplo n.º 10
0
        protected override void SwapAssignmentOnSlot(uint slotId)
        {
            //Find the inputLine
            int count = 0, statementIndex = -1, inputLineIndex = -1;
            int inputSlotIndex = this.GetSlotIndex(slotId);
            VariableLine inputLine = new VariableLine();
            foreach (KeyValuePair<int, List<VariableLine>> kvp in this.inputLines)
            {
                for (int i = 0; i < kvp.Value.Count; i++)
                {
                    if (count == inputSlotIndex)
                    {
                        inputLine = kvp.Value[i];
                        inputLineIndex = i;
                        break;
                    }
                    count++;
                }

                if (inputLineIndex != -1)
                {
                    statementIndex = kvp.Key;
                    break;
                }
            }

            //Find the outputLine
            int outputSlotIndex = 0;
            VariableLine outputLine = new VariableLine();
            foreach (VariableLine variableLine in this.outputLines)
            {
                if (variableLine.line == inputLine.line)
                {
                    outputLine = variableLine;
                    break;
                }
                outputSlotIndex++;
            }

            //Swap inputLine and outputLine
            List<VariableLine> variableLines = new List<VariableLine>();
            this.inputLines.TryGetValue(statementIndex, out variableLines);
            variableLines.RemoveAt(inputLineIndex);
            variableLines.Insert(inputLineIndex, outputLine);
            this.outputLines.RemoveAt(outputSlotIndex);
            this.outputLines.Insert(outputSlotIndex, inputLine);

            //Swap assignment in compilableText
            this.compilableText = Utilities.SwapAssignment(this.compilableText, inputLine.line);

            //Update variable mapping
            RuntimeStates runtimeStates = graphController.GetRuntimeStates();
            runtimeStates.UpdateVariablesDefinedInNode(this, false);
        }