Skip to content

Need to Fix Unit Test Code for Some JavaScript Problems of HumanEval-X #45

@gugeonmo

Description

@gugeonmo

Case 1: Missing unit test function call

Problems 32, 119, and 151 have no unit test function call in their "test" code.
For example, the "test" code of Problem 32 is as follows. (Note that there is no function call for the testfindZero function)

const testfindZero = () => {
  const getRandomIntInclusive = (min = 0, max = 9) => {
    min = Math.ceil(min)
    max = Math.floor(max)
    return Math.floor(Math.random() * (max - min + 1)) + min
  }

  for (let i = 0; i < 100; i++) {
    let ncoeff = 2 * getRandomIntInclusive(1, 4);
    let coeffs = [];
    for (let j = 0; j < ncoeff; j++) {
      let coeff = getRandomIntInclusive(-10, 10);
      if (coeff === 0)
        coeff = 1;
      coeffs.push(coeff);
    }
    let solution = findZero(coeffs);
    console.assert(Math.abs(poly(coeffs, solution)) < 1e-4);
  }
}

Problems are always regarded as passed problems if there is no unit test function call.
Please add the unit test function call at the end of "test" code for problems 32, 119, and 151.

Case 2: Typo in the unit test

The problem 112 has typo in its unit test code.
Currently, the "test" code of problem 112 is as follows. (Note the position of the third closing parenthesis)

const testReverseDelete = () => {
  console.assert(JSON.stringify(reverseDelete('abcde', 'ae'))) ===
    JSON.stringify(['bcd', false])
  console.assert(JSON.stringify(reverseDelete('abcdef', 'b'))) ===
    JSON.stringify(['acdef', false])
  console.assert(JSON.stringify(reverseDelete('abcdedcba', 'ab'))) ===
    JSON.stringify(['cdedc', true])
  console.assert(JSON.stringify(reverseDelete('dwik', 'w'))) ===
    JSON.stringify(['dik', false])
  console.assert(JSON.stringify(reverseDelete('a', 'a'))) ===
    JSON.stringify(['', true])
  console.assert(JSON.stringify(reverseDelete('abcdedcba', ''))) ===
    JSON.stringify(['abcdedcba', true])
  console.assert(JSON.stringify(reverseDelete('abcdedcba', 'v'))) ===
    JSON.stringify(['abcdedcba', true])
  console.assert(JSON.stringify(reverseDelete('vabba', 'v'))) ===
    JSON.stringify(['abba', true])
  console.assert(JSON.stringify(reverseDelete('mamma', 'mia'))) ===
    JSON.stringify(['', true])
}
testReverseDelete()

The problem 112 is always regarded as passed due to the wrong position of the closing parenthesis.
You should move the third closing parenthesis to the end of the sentence for each unit test code.

Case 3: There is no tuple in JavaScript

Problems 107, 136, 155 use tuple syntax of Python in their unit test.
However, there is no tuple syntax in JavaScript, which leads to unexpected behaviors (e.g., all unit tests fail)
For example, the "test" code of problem 107 is as follows.

const testEvenOddPalindrome = () => {
  console.assert(
    JSON.stringify(evenOddPalindrome(123)) === JSON.stringify((8, 13))
  )
  console.assert(
    JSON.stringify(evenOddPalindrome(12)) === JSON.stringify((4, 6))
  )
  console.assert(
    JSON.stringify(evenOddPalindrome(3)) === JSON.stringify((1, 2))
  )
  console.assert(
    JSON.stringify(evenOddPalindrome(63)) === JSON.stringify((6, 8))
  )
  console.assert(
    JSON.stringify(evenOddPalindrome(25)) === JSON.stringify((5, 6))
  )
  console.assert(
    JSON.stringify(evenOddPalindrome(19)) === JSON.stringify((4, 6))
  )
  console.assert(
    JSON.stringify(evenOddPalindrome(9)) === JSON.stringify((4, 5))
  )
  console.assert(
    JSON.stringify(evenOddPalindrome(1)) === JSON.stringify((0, 1))
  )
}

testEvenOddPalindrome()

You need to use list instead of tuple.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions