csharp: Wrong Expected Values in WeighingMachine

[Fact]
    public void Get_us_display_weight_pounds()
    {
        var wm = new WeighingMachine();
        wm.InputWeight = 60m;// no default unit supplied hence assumed kg
        Assert.Equal(132, wm.USDisplayWeight.Pounds);// 60 kg == 132.277 pounds  // **precision lost** 
    }

    [Fact]
    public void Get_us_display_weight_ounces()
    {
        var wm = new WeighingMachine();
        wm.InputWeight = 60m;// no default unit supplied hence assumed kg
        Assert.Equal(4, wm.USDisplayWeight.Ounces); // **60 kg  = 2116.44 ounces** 
    }

    [Fact]
    public void Input_pounds_and_get_us_display_weight_pounds()
    {
        var wm = new WeighingMachine();
        wm.Units = Units.Pounds;
        wm.InputWeight = 175.5m;
        Assert.Equal(175, wm.USDisplayWeight.Pounds); // **precision lost**
    }

    [Fact]
    public void Input_pounds_and_get_is_display_weight_ounces()
    {
        var wm = new WeighingMachine();
        wm.Units = Units.Pounds;
        wm.InputWeight = 175.5m;
        Assert.Equal(8, wm.USDisplayWeight.Ounces); // **175.5 pounds == 2808 ounces**
    }

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

@18-F-cali That looks really good! My only suggestion would be to move some of the introduction text to the individual tasks. For example, moving the bit about the tare adjustment from the instruction text to the task. In general, it’s best to explain things in the tasks and have the introduction text just setup the general context. That makes it easier for students to know what the task is about without having to scroll back.

Thanks! As for the tests/instructions: I think they’ll mostly be fairly self-explanatory. The goal is to have the student slowly build a working implementation, so that means starting with the things that don’t have any dependencies and are simple to implement and then moving on to more involved tasks.

The one potentially less obvious part of my proposal is the initialization of the TareAdjustment to the value 5. We could maybe having this be explained in the task using something like this: "Most weighing machines are not perfectly accurate, and tests have found that they usually have a bias towards overestimating the weight. To remedy this, implement the TareAdjustment property to the value 5.

We could follow this up with a later task that allows for adjusting the tare adjustment, which could give students the opportunity to convert a getter-only property to a get-set property.

Note that the above proposal would also require some changes to the tasks and tests, but we can discuss those once we’re happy with the design.

I think I’ll only have time to look at this next week, sorry.

Brilliant. For #1645 it might be best if we discussed the approach before you start coding, as it involves tweaking the design.

@18-F-cali Having done this exercise myself, it is indeed a slightly problematic exercise. I’ve created three issues:

Let me know if you are interested in working on these issues.

I’ll look into this!