public void AssignVariableIndexToStaticList() { var program = MDKFactory.CreateProgram <Program>(); var command = program.ParseCommand("assign myList[0] to [\"one\", \"two\", \"three\"]"); Assert.IsTrue(command is ListVariableAssignmentCommand); ListVariableAssignmentCommand assignmentCommand = (ListVariableAssignmentCommand)command; Assert.IsTrue(assignmentCommand.list.expectedList is InMemoryVariable); InMemoryVariable listName = (InMemoryVariable)assignmentCommand.list.expectedList; Assert.AreEqual("myList", listName.variableName); List <Variable> listIndexes = CastList(assignmentCommand.list.index.GetValue()).GetTypedValue().GetValues(); Assert.AreEqual(1, listIndexes.Count); Assert.AreEqual(0, CastNumber(listIndexes[0].GetValue()).GetTypedValue()); Primitive list = assignmentCommand.value.GetValue(); Assert.AreEqual(Return.LIST, list.GetPrimitiveType()); List <Variable> listItems = CastList(list).GetTypedValue().GetValues(); Assert.AreEqual(3, listItems.Count); Assert.AreEqual("one", CastString(listItems[0].GetValue()).GetTypedValue()); Assert.AreEqual("two", CastString(listItems[1].GetValue()).GetTypedValue()); Assert.AreEqual("three", CastString(listItems[2].GetValue()).GetTypedValue()); }
public void AssignVariableIndexToVariable() { var program = MDKFactory.CreateProgram <Program>(); var command = program.ParseCommand("assign myList[0] to \"value\""); Assert.IsTrue(command is ListVariableAssignmentCommand); ListVariableAssignmentCommand assignmentCommand = (ListVariableAssignmentCommand)command; Assert.IsTrue(assignmentCommand.list.expectedList is InMemoryVariable); InMemoryVariable listName = (InMemoryVariable)assignmentCommand.list.expectedList; Assert.AreEqual("myList", listName.variableName); List <Variable> listIndexes = CastList(assignmentCommand.list.index.GetValue()).GetTypedValue().GetValues(); Assert.AreEqual(1, listIndexes.Count); Assert.AreEqual(0, CastNumber(listIndexes[0].GetValue()).GetTypedValue()); Primitive value = assignmentCommand.value.GetValue(); Assert.AreEqual("value", CastString(value).GetTypedValue()); }
public void AssignListAtIndexValuesToAnotherList() { var program = MDKFactory.CreateProgram <Program>(); var command = program.ParseCommand("assign myList[1, 2, 3] to [0]"); Assert.IsTrue(command is ListVariableAssignmentCommand); ListVariableAssignmentCommand assignmentCommand = (ListVariableAssignmentCommand)command; Assert.IsTrue(assignmentCommand.list.expectedList is InMemoryVariable); InMemoryVariable listName = (InMemoryVariable)assignmentCommand.list.expectedList; Assert.AreEqual("myList", listName.variableName); List <Variable> listIndexes = CastList(assignmentCommand.list.index.GetValue()).GetTypedValue().GetValues(); Assert.AreEqual(3, listIndexes.Count); Assert.AreEqual(1, CastNumber(listIndexes[0].GetValue()).GetTypedValue()); Assert.AreEqual(2, CastNumber(listIndexes[1].GetValue()).GetTypedValue()); Assert.AreEqual(3, CastNumber(listIndexes[2].GetValue()).GetTypedValue()); List <Variable> assignedValue = CastList(assignmentCommand.value.GetValue()).GetTypedValue().GetValues(); Assert.AreEqual(1, assignedValue.Count); Assert.AreEqual(0f, assignedValue[0].GetValue().GetValue()); }