01-edu / Branch-Mobile

🎯 Repository for the Mobile branch Dart tests.
1 stars 1 forks source link

Week1/day1/ex8 - maxNum #4

Closed jotapero closed 2 years ago

jotapero commented 2 years ago

Exercise is not explicit, example function and summary don't explain what the tests intend. Program wants a function that takes maximum of 3 numbers, but tests compare only the highest of the 3 arguments.

void main() {
  group('maxNum', () {
    for (int i = 0; i < 50; i++) {
      Random rnd = new Random();
      int first = -100 + rnd.nextInt(200);
      int second = -100 + rnd.nextInt(200);
      int third = -100 + rnd.nextInt(200);

// this test checks for the maximum value on the list

      test('maxNum(${first}, ${second}, ${third})', () {
        expect(student.maxNum(first, second, third),
            equals([first, second, third].reduce(max)));
      });
    }
  });
}

What is the purpose of the exercise?

sakenism commented 2 years ago

The purpose was to let students know about ternary operators, and their existence in dart. It is not super necessary concept, but we wanted them to know about it.

jotapero commented 2 years ago

Got it, thank you