Problem-specifications: Generating tests for "all-your-base" exercise

Created on 20 Dec 2016  路  6Comments  路  Source: exercism/problem-specifications

Hi there!

I've been working on adding a test generator for the all-your-base exercise for exercism/xruby and I've run into a bit of a snag.

Everything works perfectly until I get to the last 13 (if I counted correctly) exercises that are left undefined. As far as I'm able to tell, and I certainly could be missing something, these tests aren't easy (possible?) to generate from individual tracks. Is that correct?

If so, I'm wondering if theres a way that we could add more information to the canonical-data so that different tracks could generate their tests based on the following (from the data documentation):

It's up to each track do decide:

1. What's the canonical representation of zero?
    - []?
    - [0]?

2. What representations of zero are allowed?
     - []?
     - [0]?
     - [0,0]?

3. Are leading zeroes allowed?

4. How should invalid input be handled?

Though, I'm really not to sure how that would work...

Have any other tracks successfully implemented a test generator for all-your-base? I looked through a couple of the other language repositories, but I wasn't able to find anything.

Thank you so much for your time!!

Most helpful comment

Hi @tommyschaefer

I also allowed leading zeroes in OCaml (it felt more natural, even though it complicates the implementation).

The OCaml test generator works off a template file (one for each exercise), and substitutes in a None (OCaml equivalent of null, to indicate failure) for the null it sees in the json. Since this isn't what I wanted, I just hand-edited.

I see the test generator as a tool to help in translating exercises into OCaml, and to help updating tests when the json changes, but it will still need some human intervention for certain exercises.

All 6 comments

Aren't the last examples with expected: null error cases?
So you need to return/raise an appropriate error value.

Can you help us by asking a specific question about a specific case?

@stevejb71 has created a test generated and converted all-your-base with it for the xocaml track.

He probably faces similar questions, so maybe he can weigh in on the matter?

@Insti

Aren't the last examples with expected: null error cases?

Not necessarily, for example the leading zeros test:

{
  "description"  : "leading zeros",
  "input_base"   : 7,
  "input_digits" : [0, 6, 0],
  "output_base"  : 10,
  "expected"     : null
}

This is a case where tracks can either implement leading zeros as valid or invalid.

So in the Ruby implementation, we do allow leading zeros:

def test_leading_zeros
    skip
    digits = [0, 6, 0]
    input_base = 7
    output_base = 10
    expected = [4, 2]

    ...

But the Javascript implementation does not:

xit('leading zeros', function () {
  expect(function () {
    converter.convert([0, 6, 0], 7, 10);
  }).toThrow(new Error('Input has wrong format'));
});

@dvberkel Thanks so much! I'll check out that implementation 馃槃

Hi @tommyschaefer

I also allowed leading zeroes in OCaml (it felt more natural, even though it complicates the implementation).

The OCaml test generator works off a template file (one for each exercise), and substitutes in a None (OCaml equivalent of null, to indicate failure) for the null it sees in the json. Since this isn't what I wanted, I just hand-edited.

I see the test generator as a tool to help in translating exercises into OCaml, and to help updating tests when the json changes, but it will still need some human intervention for certain exercises.

Thank you so much for the help @Insti, @dvberkel, and @stevejb71!

I'm going to go ahead and close this issue since, with help from you all, I was able to get this working 馃槃

Thanks again everyone!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Mavelous picture Mavelous  路  4Comments

kytrinyx picture kytrinyx  路  4Comments

petertseng picture petertseng  路  3Comments

shaleh picture shaleh  路  3Comments

budmc29 picture budmc29  路  3Comments