add support for translating Dart by devoncarew · Pull Request #153 · nuprl/MultiPL-E (original) (raw)

Here's the output for python3 test.py humaneval_to_dart ../datasets/originals/HumanEval_53_add.py:

// Add two numbers x and y
// >>> add(2, 3)
// 5
// >>> add(5, 7)
// 12
int add(int x, int y) {

********************************************************************************
void main() {
  final candidate = add;

  expect(candidate(0, 1), 1);
  expect(candidate(1, 0), 1);
  expect(candidate(2, 3), 5);
  expect(candidate(5, 7), 12);
  expect(candidate(7, 5), 12);

  print('success');
}

void expect(dynamic a, dynamic b) {
  if (a == b) return;

  if (a is List && b is List) {
    expectList(a, b);
  } else if (a is Map && b is Map) {
    expectMap(a, b);
  } else {
    throw '$a != $b';
  }
}

void expectList(List a, List b) {
  if (a.length != b.length) throw 'list lengths are not equal';

  for (var i = 0; i < a.length; i++) {
    expect(a[i], b[i]);
  }
}

void expectMap(Map a, Map b) {
  if (a.length != b.length) throw 'map lengths are not equal';

  for (var key in a.keys) {
    expect(a[key], b[key]);
  }
}
********************************************************************************
['\nfunction ', '\n/*', '\n//', '\nclass']
********************************************************************************
Translation succeeded. Examine the output above to verify that it is correct.

And a DartPad snippet for the above: https://dartpad.dev/?id=8f9fe06a67328d6c82c35c202915227e