Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
fix(school): reverse all condition in checks
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaBrighi committed Jul 11, 2023
1 parent f7cd115 commit edfb6c5
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface Class {
* @throws IllegalArgumentException if the name is blank
*/
fun create(name: String): Class {
check(name.isBlank()) { "name cannot be blank" }
check(name.isNotBlank()) { "name cannot be blank" }
return ClassImpl(name)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ interface School {
* @throws IllegalArgumentException if the name or the city is blank
*/
fun create(name: String, city: String): School {
check(name.isBlank()) { "name cannot be blank" }
check(city.isBlank()) { "city cannot be blank" }
check(name.isNotBlank()) { "name cannot be blank" }
check(city.isNotBlank()) { "city cannot be blank" }
return SchoolImpl(name, city)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ object CalendarEventFactory {
subject: Subject,
module: String? = null,
): WeekLesson {
check(subject.isBlank()) {
check(subject.isNotBlank()) {
"subject cannot be blank"
}
check(startTime.isAfter(endTime)) {
check(!startTime.isAfter(endTime)) {
"startTime cannot be after endTime"
}
check(fromDate.isAfter(toDate)) {
check(!fromDate.isAfter(toDate)) {
"fromDate cannot be after toDate"
}
return WeekLessonImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal data class SchoolCalendarImpl(
}

override fun addLessons(lessons: Set<WeekLesson>): SchoolCalendar {
check(lessons.any { lesson -> this.lessons.any { it == lesson } }) {
check(!lessons.any { lesson -> this.lessons.any { it == lesson } }) {
"lessons must not be in current lessons"
}
val checkOverlappingStudents = lessons.any { lesson ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal data class SchoolImpl(
* @throws IllegalArgumentException if the class is already in the school
*/
override fun addClass(classToAdd: Class): School {
check(classes.contains(classToAdd)) {
check(!classes.contains(classToAdd)) {
"class already in school"
}
return copy(classes = classes + classToAdd)
Expand All @@ -64,7 +64,7 @@ internal data class SchoolImpl(
* @throws IllegalArgumentException if the student is already in the school
*/
override fun addStudent(student: Student): School {
check(students.contains(student)) {
check(!students.contains(student)) {
"student already in school"
}
return copy(students = students + student)
Expand All @@ -77,7 +77,7 @@ internal data class SchoolImpl(
* @throws IllegalArgumentException if the professor is already in the school
*/
override fun addProfessor(professor: Professor): School {
check(professors.contains(professor)) {
check(!professors.contains(professor)) {
"professor already in school"
}
return copy(professors = professors + professor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ interface Professor : Person {
name: String,
surname: String,
): Professor {
check(email.isBlank()) { "email cannot be blank" }
check(name.isBlank()) { "name cannot be blank" }
check(surname.isBlank()) { "surname cannot be blank" }
check(email.isNotBlank()) { "email cannot be blank" }
check(name.isNotBlank()) { "name cannot be blank" }
check(surname.isNotBlank()) { "surname cannot be blank" }
return ProfessorImpl(email, name, surname)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ interface Student : Person {
name: String,
surname: String,
): Student {
check(email.isBlank()) { "email cannot be blank" }
check(name.isBlank()) { "name cannot be blank" }
check(surname.isBlank()) { "surname cannot be blank" }
check(email.isNotBlank()) { "email cannot be blank" }
check(name.isNotBlank()) { "name cannot be blank" }
check(surname.isNotBlank()) { "surname cannot be blank" }
return StudentImpl(email, name, surname)
}
}
Expand Down

0 comments on commit edfb6c5

Please sign in to comment.