Skip to content

Instantly share code, notes, and snippets.

@tranductam2802
Created January 13, 2021 06:22
Show Gist options
  • Save tranductam2802/61c439aadc0124bb0b6545c127291505 to your computer and use it in GitHub Desktop.
Save tranductam2802/61c439aadc0124bb0b6545c127291505 to your computer and use it in GitHub Desktop.
02. Dart method (for test)
Assign data to result
/// Update value for result
void plus(int a, int b, Result result) {
}
class Result {
int value = 0;
}
// Testcase
// void main() {
// try {
// final result = Result();
// final str = plus(2, 3, result);
// if (result == 5) {
// _result(true);
// } else if (result == 0) {
// _result(false, ['Test failed. It looks like you forgot assign data!']);
// } else {
// _result(false, ['That\'s not quite right. Keep trying!']);
// }
// } catch (e) {
// _result(false, ['Tried calling plus(2, 3), but received an exception: ${e.runtimeType}']);
// }
// }
void plus(int a, int b, Result result) {
result.value = a + b;
}
void main() {
try {
final result = Result();
final str = plus(2, 3, result);
if (result == 5) {
_result(true);
} else if (result == 0) {
_result(false, ['Test failed. It looks like you forgot assign data!']);
} else {
_result(false, ['That\'s not quite right. Keep trying!']);
}
} catch (e) {
_result(false, ['Tried calling plus(2, 3), but received an exception: ${e.runtimeType}']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment