public void testCollectionLiteral(String expression, String expectedElementTypeName, String collectionName, int partsSize, CollectionKindEnum collectionKind) { CollectionLiteralExp literalExp = doTestOK(expression); Assert.IsTrue(literalExp.getType() is CollectionType); CollectionType collectionType = (CollectionType)literalExp.getType(); Assert.AreEqual(collectionName, collectionType.getName()); Assert.AreEqual(expectedElementTypeName, collectionType.getElementType().getName()); Assert.AreEqual(partsSize, literalExp.getParts().Count); Assert.AreEqual(collectionKind, literalExp.getKind()); }
public void testSetLiteral_07() { CollectionLiteralExp literalExp = doTestOK("Bag{ Set{1, 2}, Set{4, 8} } "); CoreClassifier expectedType = (CoreClassifier)environment.lookup("Integer"); Assert.IsNotNull(expectedType); Assert.IsTrue(literalExp.getType() is BagType); CollectionType collectionType = (CollectionType)literalExp.getType(); Assert.IsTrue(collectionType.getElementType() is SetType); Assert.AreEqual(2, literalExp.getParts().Count); Assert.AreEqual(CollectionKindEnum.BAG, literalExp.getKind()); }
protected CollectionLiteralExp checkCollectionLiteralExp(OclExpression oclExpression, String type) { Assert.IsTrue(oclExpression is CollectionLiteralExp); CollectionLiteralExp exp = (CollectionLiteralExp)oclExpression; Assert.AreEqual(type, exp.getType().getName()); return(exp); }
public void testCollectionLiteralExp() { AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage()); CollectionLiteralExp exp = factory1.createCollectionLiteralExp(createCollectionParts(), factory1.createSetType( getClassifier("Integer"))); Assert.AreEqual("Set{ 100, 200, 300 }", exp.ToString()); Assert.AreEqual("Set(Integer)", exp.getType().getName()); CollectionLiteralExp exp2 = factory1.createCollectionLiteralExp(createCollectionParts(), factory1.createSetType( getClassifier("Integer"))); Assert.AreEqual("Set{ 100, 200, 300 }", exp2.ToString()); Assert.AreEqual("Set(Integer)", exp2.getType().getName()); exp = factory1.createCollectionLiteralExp(createCollectionParts(), factory1.createBagType(getClassifier("Integer"))); Assert.AreEqual("Bag{ 100, 200, 300 }", exp.ToString()); Assert.AreEqual("Bag(Integer)", exp.getType().getName()); exp = factory1.createCollectionLiteralExp(createCollectionParts(), factory1.createSequenceType(getClassifier("Integer"))); Assert.AreEqual("Sequence{ 100, 200, 300 }", exp.ToString()); Assert.AreEqual("Sequence(Integer)", exp.getType().getName()); exp = factory1.createCollectionLiteralExp(createCollectionParts(), factory1.createOrderedSetType(getClassifier("Integer"))); Assert.AreEqual("OrderedSet{ 100, 200, 300 }", exp.ToString()); Assert.AreEqual("OrderedSet(Integer)", exp.getType().getName()); OclExpression elem1 = factory1.createIntegerLiteralExp(100, getClassifier("Integer")); OclExpression elem2 = factory1.createIntegerLiteralExp(200, getClassifier("Integer")); CollectionRange range = factory1.createCollectionRange(elem1, elem2); List <object> parts = new List <object> (); parts.Add(range); exp = factory1.createCollectionLiteralExp(parts, factory1.createSetType(getClassifier("Integer"))); Assert.AreEqual("Set{ 100 .. 200 }", exp.ToString()); Assert.AreEqual("Set(Integer)", exp.getType().getName()); }
private void doTestSameCollectionTypeInstance(String expression1, String expression2, bool isEqual) { CollectionLiteralExp literalExp1 = doTestOK(expression1); Assert.IsTrue(literalExp1.getType() is CollectionType); CollectionType collectionType1 = (CollectionType)literalExp1.getType(); CollectionLiteralExp literalExp2 = doTestOK(expression2); Assert.IsTrue(literalExp2.getType() is CollectionType); CollectionType collectionType2 = (CollectionType)literalExp2.getType(); if (isEqual) { Assert.AreEqual(collectionType1.getName(), collectionType2.getName()); } else { Assert.IsFalse(collectionType1.getName().Equals(collectionType2.getName())); } }