News for hackers. Stuff that matters.
Re:Save the code or save the tests? (2020) by zeroimpl on Wednesday June 09, 2021 @09:53PM (#27455856)
Something like:

    assertEquals(0, add(0,0))
    assertEquals(1, add(0,1))
    assertEquals(2, add(1,1))
    assertEquals(8, add(3,5))
    assertEquals(-3, add(2,-5))
PS: This kind of proves why a test is a lot less useful than the algorithm. Try figuring out how to implement "add" from the above test.
Re:Save the code or save the tests? (2020) by anonytrary on Wednesday June 09, 2021 @11:37PM (#27456396)
Personally I see this a lot and I'm not a fan:

  it('should work', () => {
    inputOutputPairs.forEach(([input, output]) => {
      expect(testedFunction(input)).equals(output);
    })
  })
Tests are way more useful when they are written with the intent of acting as documentation. If I had to give this test a grade (from F- to A+), it would get a D+. It catches regressions, yet does an absolutely horrid job of explaining the intent behind testedFunction.
Re:Save the code or save the tests? (2020) by ramses0 on Thursday June 10, 2021 @12:34PM (#27462603)

    cases = [
      { in: 1, arg: 2, expected: 3, message: "base case" },
      { in: 2, arg: -2, expected: 0, message: "negative numbers" },
      ...
    ]
    for ( c in cases ) {
      actual = obj.do( c.in, c.arg )
      assert( actual == c.expected, c.message )
    }
see: http://fit.c2.com/ ... table-based testing, "cases" and "drivers"