0

draw of my situation
In the link above, we can see the class Student and Class. I want to make an invariant constraint to make sure a Student can't register for more than 5 classes each sessionYear.

With this constraint, I can determine if Student as more than 5 classes

context Student
inv maxClassStudent: classTaken->collect(sessionYear)->size() < 6

But, what I want is to find the size for a collection formed only with the same sessionYear. In other words, I wish to make a collection for every different sessionYear to verify if, for that year, the Student had less than 6 classes.

I thought that I could maybe make use of forAll(c1,c2|c1<>c2 implies c1.sessionYear <> c2.sessionYear) or something similar to difference Class based on its sessionYear, but I can't seem to figure it out.

Takyon
  • 59
  • 6

1 Answers1

0

Hard problems are often soluble by breaking them into smaller pieces...

let sessionYears = classTaken->collect(sessionYear)->asSet() in sessionYears->forAll(sy | classTaken->select(sessionYear = sy)->size() < 6)

Ed Willink
  • 1,205
  • 7
  • 8
  • oh, so the select is the answer here. I had a hard time figuring out how to break my collection into smaller pieces, but with `select(sessionYear = sy)`, I get a collection for every different `sy`. Thanks a lot – Takyon Nov 11 '18 at 19:45