#!/usr/bin/env python

import coral

L = coral.lang.UML14

s1 = coral.Set()
s2 = coral.Set()

classes = [ L.Class() for i in xrange(10) ]

for i in xrange(len(classes)):
    classes[i].name = "Class %d" % i

for i in range(0, 6):
    s1.insert(classes[i])

for i in range(4, 10):
    s2.insert(classes[i])

s3 = s1.clone()

print "--before--"
for i in s3: print i

s3.intersectWith(s2)

print "--after--"
for i in s3: print i

assert classes[0] not in s3
assert classes[1] not in s3
assert classes[2] not in s3
assert classes[3] not in s3
assert classes[4] in s3
assert classes[5] in s3
assert classes[6] not in s3
assert classes[7] not in s3
assert classes[8] not in s3
assert classes[9] not in s3

######################################################################

print
print
print

b1 = coral.Bag()
b2 = coral.Bag()

classes = [ L.Class() for i in xrange(5) ]

for i in xrange(len(classes)):
    classes[i].name = "Class %d" % i

for i in range(0, 5):
    b1.insert(classes[i])
b1.insert(classes[1])
b1.insert(classes[3])
b1.insert(classes[3])

for i in range(0, 5):
    b2.insert(classes[i])
b2.insert(classes[1])
b2.insert(classes[1])
b2.insert(classes[3])

b3 = b1.clone()

print "--before (b3)--"
for i in b3: print i
print "--before (b2)--"
for i in b2: print i

b3.intersectWith(b2)

print "--after (b3)--"
for i in b3: print i

assert b3.count(classes[0]) == 1
assert b3.count(classes[1]) == 2
assert b3.count(classes[2]) == 1
assert b3.count(classes[3]) == 2
assert b3.count(classes[4]) == 1

######################################################################

print
print
print

p = coral.Project()
c1 = L.Class()
c1.__setProject__(p)
assert len(p.contents()) == 1

c2 = coral.ModelCopy_One(c1)

assert c2.__getProject__() == p
assert len(p.contents()) == 2

c3 = coral.ModelCopy_One(c1, coral.MODELCOPY_DONT_ATTACH_TO_PARENTS)

assert c3.__getProject__() == None
assert len(p.contents()) == 2


