exercism / chapel

Exercism exercises in Chapel.
https://exercism.org/tracks/chapel
MIT License
3 stars 4 forks source link

Meetup: what would a sample test look like? #43

Closed kytrinyx closed 2 years ago

kytrinyx commented 2 years ago

Here is a sample entry in the canonical data for the meetup problem.

{
  "uuid": "b08a051a-2c80-445b-9b0e-524171a166d1",
  "description": "when third Wednesday is some day in the middle of the third week",
  "property": "meetup",
  "input": {
    "year": 2013,
    "month": 7,
    "week": "third",
    "dayofweek": "Wednesday"
  },
  "expected": "2013-07-17"
}

The corresponding test for this data in Ruby is:

  def test_when_third_wednesday_is_some_day_in_the_middle_of_the_third_week
    meetup = Meetup.new(7, 2013).day(:wednesday, :third)
    assert_equal Date.parse("2013-07-17"), meetup
  end

In C# it's like this:

    public void Third_wednesday_of_july_2013()
    {
        var sut = new Meetup(7, 2013);
        var expected = new DateTime(2013, 7, 17);
        Assert.Equal(expected, sut.Day(DayOfWeek.Wednesday, Schedule.Third));
    }

The exercise doesn't mandate any particular implementation. What would the test look like in Chapel if the solution is idiomatic?

If I have an idea what it needs to look like I can generate the exercise stub.

lucaferranti commented 2 years ago

o-ho, sorry I thought I had replied this. After having looked at the exercise description and JSON data, I think there are two approaches for this exercise

  1. meetup returns an object of time date. In this case the test could be something like

    test.assertEqual(meetup(2013, 8, "teenth", "Monday"), new date(2013, 8, 19));
  2. have meetup return a string. In which case the test would be

    test.assertEqual(meetup(2013, 8, "teenth", "Monday"), "2013-8-19");

I don't have an opinion on which one is better. The first case is more explicit and automatically guides the student to use the Time module, which has useful out-of-the-box functionalities to solve the problem.

The second method is less explicit. using Time is probably still the best idea, but in principle the student is free to implement everything themselves. The extra step date -> string is fairly trivial so it does not increase complexity itself.

Since this is a medium/hard exercise, how would you feel about going with option two? We can have as hint to check out the Time module. Once we have concepts we could link both this and ´gigasecondto thedatetime` concept and have gigasecond as prerequisite.

kytrinyx commented 2 years ago

I think I would prefer to use the Time option, in the sense that reaching for a time object when dealing with datetimes is what I feel like people should do, and so the obfuscation (if one can say that) of comparing against a string seems like it's not helping use the language in an idiomatic way, if that makes sense.

I need to double-check the bit about prerequisites. I think only concept exercises are meant to be prerequisites for practice exercises (but could be wrong; we've changed how all the pieces fit together over the years).

lucaferranti commented 2 years ago

sorry I forgot to answer (again). I think it makes sense, let's go with the explicit Time module. Do you have all pieces to generate the stub?

I think only concept exercises are meant to be prerequisites for practice exercises

This is also my understanding, but I don't think we need to worry about this, we can add in instructions.append.md a note as did in the other exercises

kytrinyx commented 2 years ago

Do you have all pieces to generate the stub?

I think I have what I need. I'll generate it, and if something looks off, holler and I can tweak and regenerate.

lucaferranti commented 2 years ago

fixed in #50