WeighingMachineTests don't compile

After submission:

WeighingMachineTests.cs(27,21): error CS0664: Literal of type double cannot be implicitly converted to type 'float'; use an 'F' suffix to create a literal of this type
WeighingMachineTests.cs(44,21): error CS0664: Literal of type double cannot be implicitly converted to type 'float'; use an 'F' suffix to create a literal of this type
WeighingMachineTests.cs(54,21): error CS0664: Literal of type double cannot be implicitly converted to type 'float'; use an 'F' suffix to create a literal of this type
WeighingMachineTests.cs(64,21): error CS0664: Literal of type double cannot be implicitly converted to type 'float'; use an 'F' suffix to create a literal of this type
WeighingMachineTests.cs(74,29): error CS0266: Cannot implicitly convert type 'double' to 'float'. An explicit conversion exists (are you missing a cast?)
WeighingMachineTests.cs(84,29): error CS0664: Literal of type double cannot be implicitly converted to type 'float'; use an 'F' suffix to create a literal of this type

I fixed this problem locally by doing what the messages suggest, add f to the floating-point literals.

Is there a way you can change WeighingMachine.cs instead of changing the tests?

@keiraville I suppose changing all mention of float to double in WeighingMachine.cs might help, but the class comes with some code template, and everyone who works on the exercise would have to go through the same tedious hack. Surely, fixing the tests is the right thing to do.

1 Like

Message to a mod:
I mistakenly posted this in Programming forum, but it’s a better fit for “Exercism Support”. Please move to that forum.

The code template does not specify types for the various properties.

class WeighingMachine
{
    // TODO: define the 'Precision' property

    // TODO: define the 'Weight' property

    // TODO: define the 'DisplayWeight' property

    // TODO: define the 'TareAdjustment' property
}

The instructions mention

var wm = new WeighingMachine(precision: 3);
wm.Weight = 60.5;

//  => wm.Weight == 60.5

without any f, this suggests the tests are consistent with the instructions.

Your post is in the right place. We use the programming category for most code/language specific discussions.

@keiraville You’re right, I changed the main code to use double, and the submission went through. Thank you.