#!/usr/bin/env python
import coral
M = coral.loadModel("tmp/uml14_with_operation.xml")
L = coral.smd2lang(M)
from coral.lgen.lang2smd import lang2smd

M2 = lang2smd(L)
coral.saveModel("tmp/out_PRoundTripOperations.xml", M2)

M3 = coral.loadModel("tmp/out_PRoundTripOperations.xml")

op1 = M.elements.select(lambda x: x.name == "Classifier")[0].operations[0]
op2 = M2.elements.select(lambda x: x.name == "Classifier")[0].operations[0]
op3 = M3.elements.select(lambda x: x.name == "Classifier")[0].operations[0]

for i in xrange(len(op1.code)):
    print "x1", op1.code[i], "y1"
    print "x2", op2.code[i], "y2" 
    print "x3", op3.code[i], "y3"
    assert op1.code[i].__getString__() == op2.code[i].__getString__()
    assert op1.code[i].__getString__() == op3.code[i].__getString__()

print len(op1.code)
print len(op2.code)
print len(op3.code)
assert len(op1.code) == len(op2.code)
assert len(op2.code) == len(op3.code)
