01-edu / Branch-Mobile

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

Week1/day1/ex6 - namedOptionalSum #2

Closed jotapero closed 1 year ago

jotapero commented 2 years ago

There appears to be a problem with the test cases, if a student were to bruteforce his way through the exercise then there's a solution that passes the tests but prints out incorrect outputs:

namedOptionalSum ({int? first, int? second, int? third}) {
    var sum = 0;
    if (first != null && second != null && third != null) {
        sum = first + second + third;
    };
    if (first == null && second != null && third != null) {
        sum = second + third;
    };
    if (second == null && first != null && third != null) {
        sum = first + third;
    };
    if (first == null && second == null && third != null) {
        sum = third;
    };

    return sum;
}

So with this codes all tests pass. However if we were to try this out with these values as parameters, the value should be '2' instead of '0' (which it's what it prints.

void main() {
  var res = namedOptionalSum(first: null,second: 2,third: null);
  print(res); 
}
sakenism commented 1 year ago

You are right, I added more tests to cover all the outcomes

jotapero commented 1 year ago

Thank you, it is fixed and working