I started C# recently and i have to do a project called Ray tracer challenge. For that, we need to first do some Test driven dev, then it's coding time. The problem i got is: The result that needs to be check is returned with <> instead of () and so the test, even if the values are ok, can't pass.
This is my TDD code:
[Test]
public void Adding()
{
var a = new List<double>() { 3.5, -2.0, 5.0, 1.0 }; // point
var b = new List<double>() { -2.0, 3.0, 1.0, 0.0 }; // point
Assert.AreEqual((a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3]), Addition.Add(string.Empty));
}
This is my return function:
internal static List<double> Add(string numbers)
{
return new List<double> { 1.5, 1.0, 6.0, 1.0 };
}
The result is
Adding
Source: UnitTest1.cs line 11
Duration: 158 ms
Message:
Expected: (1.5d, 1.0d, 6.0d, 1.0d)
But was: < 1.5d, 1.0d, 6.0d, 1.0d >
Stack Trace:
Tests.Adding() line 17
I can't change
Assert.AreEqual((a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3]), Addition.Add(string.Empty));
Could someone explain me please? PS: I know that testing an addition isn't really worth it, i'm mostly training on basic things.
Your assert compares this: (a[0] +... + b[3])
which is a tuple, and this: new List<double>() { 3.5,... 1.0 }
which is a list.
Since they're different collection types, the comparison does not work as expected.
Either use a List
as your assert expected value:
Assert.AreEqual(new List<double> { a[0] + ... + b[3]}, Addition.Add(string.Empty));
Or change your return function to return a Tuple
like so:
{
return (1.5, 1.0, 6.0, 1.0);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.