<ocl>
context Person inv: age>=0

<ocl>
context Person
inv: age.div(7)<7
inv: age.mod(7)<7
inv: age.max(7)<7
inv: age.min(7)<7

<ocl>
context Company inv:
  employees->iterate(
    p:Person ; b:Bag(Person)=Bag{} |
    b->including(p)
  )->includes(manager)

<ocl syntax=0>
context Person : whatever

<ocl syntax=1>
context Company inv: self.numberOfEmployees=employees->size

<ocl>
context Company inv:
manager.employers->includes(self)

<ocl>
context Person inv:
managedCompanies->forAll(employees->includes(self))

<ocl>
context Person inv:
employers.employees->forAll(age>0)

<ocl>
context Person inv:
if isMarried then
  wife->isEmpty xor husband->isEmpty
else
  wife->isEmpty and husband->isEmpty
endif

<ocl>
context LoyaltyProgram::enroll(c:Customer)
pre: not(customer->includes(c))

<ocl>
context Customer
inv: title=(if isMale=true then 'Mr' else 'Ms' endif)

<ocl>
context LoyaltyProgram
inv: self.customer->forAll(
  c1, c2 | c1<>c2 implies c1.name<>c2.name
)
inv: self.customer->isUnique(name)

<ocl>
context Membership
inv: customer.cards.membership->includes(self)

<ocl>
context Membership
inv: program.serviceLevel->includes(actualLevel)

<ocl>
context Membership
inv: loyaltyAccount.points>=0 or loyaltyAccount->isEmpty

<ocl>
context Service
inv: self.pointsEarned>0 implies not (self.pointsBurned=0)

<ocl>
context ServiceLevel
inv: loyaltyProgram.partners->includes(service.programPartner)

<ocl>
context Transaction
inv: self.program()=card.membership.program

<ocl>
context Transaction::program()
post: result=self.card.membership.program

<ocl>
context Burning
inv: self.oclIsTypeOf(Burning)=true
inv: self.oclIsKindOf(Transaction)=true

<ocl>
context Burning
inv: self.oclIsTypeOf(Transaction)=false

<ocl>
context Burning
inv: Customer.name='Customer' -- in beliebigem Kontext moeglich

<ocl>
context Burning
inv: Transaction.attributes->includesAll(Set{'points', 'date'})

<ocl>
context Burning
inv: Transaction.associationEnds->includesAll(
  Set{'serviceLevel', 'loyaltyAccount', 'card'}
)

<ocl>
context Burning
inv: Burning.supertypes=Set{Transaction}

<ocl>
context ProgramPartner
inv: self.deliveredServices.transactions->iterate(
      t:Transaction;
      result:Integer = 0 |
      if t.oclIsTypeOf(Burning) then result+t.points else result endif
    )
    <=
    self.deliveredServices.transactions->iterate(
      t:Transaction;
      result:Integer = 0 |
      if t.oclIsTypeOf(Earning) then result+t.points else result endif
    )
-- to do: 't.points' was 'points' -> default context in iterate

<ocl>
context Person inv:
Set{ 0 .. 199 }->includes(age)

<ocl types=0>
context Person inv:
Set{ 'a' .. 'z' }->includes(name.substring(1, 1))

<ocl>
context Person inv:
let firstLetter:String=name.substring(1,1) in
firstLetter = firstLetter.toUpper

<ocl types=0>
context Person inv:
let firstLetter:Person=name.substring(1,1) in
firstLetter = firstLetter.toUpper

<ocl>
context Person inv:
getIncomeAfterTax(0.3)>0

<ocl>
context Person inv:
getIncomeAfterTax(1)=0.0

<ocl types=0>
context Person inv:
getIncomeAfterTax()>0

<ocl types=0>
context Person inv:
getIncomeAfterTax(true)=0

<ocl>
context Day inv:
isWeekend = (type=DayType::sunday or type=DayType::saturday)

<ocl types=0>
context Day inv:
isWeekend = (type=DayType.sunday or type=DayType.saturday)

<ocl>
context DayType::getFollowingDay(d: DayType) post:
d=DayType::monday implies result=DayType::tuesday

<ocl>
context Person inv:
self.oclIsKindOf(royloy::Person)

<ocl>
context Person inv:
age.oclIsTypeOf(Integer)

<ocl>
context Company inv:
manager.oclIsKindOf(Person)

<ocl> 
context Person inv:
1 . oclIsKindOf(Real)

<ocl types=0>
context Customer inv:
cards->forAll(s: Service| s<>self)

<ocl>
--customers are ordered by age
context Bank inv:
Set{1 .. customer->size-1}->forAll(
  i:Integer | self.customer[i].age > self.customer[i+1].age
)

<ocl>
context Bank inv:
customer->size>100

<ocl>
--nonsense, but types are ok; element customer[0] can be treated as collection
context Bank inv:
customer[0]->size>10

<ocl types=0>
context Bank inv:
customer['Hallo'].age>0

<ocl>
context Bank inv:
customer[42].age>0

<ocl types=0>
context Company inv: manager.oclIsNew

<ocl types=0>
context Company post: manager.oclIsNew

<ocl>
context Company::getOldestEmployee() post: manager.oclIsNew

<ocl types=0>
context Company inv: manager=employees

<ocl>
context Person inv:
let a=0 in
let b=a+1 in
let c=a + self.employers->size in
let d=b*2 in
a<b and self.employers->size<c and d>0

<ocl>
context Bank inv:
oclInState(bankrupt) implies customer->isEmpty

<ocl>
context Bank inv:
self.oclInState(bankrupt) implies customer->isEmpty

<ocl>
context Bank inv:
Bank.allInstances->forAll(oclInState(bankrupt) implies customer->isEmpty)

<ocl types=0>
context Bank inv:
oclInState(test)

<ocl types=0>
context Bank inv:
self.oclInState(test)

<ocl>
context OclAny inv:
oclIsKindOf(Bank)=oclIsTypeOf(Person)
