Module Kumite Public Function Min(array() As Single) As Single Return array.Min() End Function End Module
Imports NUnit.FrameworkModule Testpublic function MinF(x, n)dim min as integerdim i as integermin = x(0)for i = 1 to nif x(i) < min thenmin = x(i)end ifnextreturn minend function- Module Kumite
- Public Function Min(array() As Single) As Single
- Return array.Min()
- End Function
- End Module
Imports NUnit.Framework <TestFixture> Public Class Kumite_KumiteShould <TestCase(New Single() {1.0f, 2.0f, 3.0f, 4.0f, 5.0f}, 1)> <TestCase(New Single() {2.3f, 1.2f, 4.6f, 8.0f, 3.0f}, 1.2f)> <TestCase(New Single() {2.3f, 1.2f, 4.6f, 2.6f, 10231.0f, -2.2f, 1.2f, 4.6f, 8.0f, 3.0f}, -2.2f)> <TestCase(New Single() {-1.0f, -1.0f}, -1.0f)> Public Sub Min_PassedArray_ReturnsMinimumValue(array() As Single, expected As Single) Dim actual As Single = Kumite.Min(array) Assert.AreEqual(expected, actual) End Sub End Class
- Imports NUnit.Framework
- <TestFixture>
Public Class AdderTest<Test>Public Sub GetsHelloWorld()dim x() as single = {4,8,4,8}dim n = 3Assert.AreEqual(4, Test.MinF(x, n))- Public Class Kumite_KumiteShould
- <TestCase(New Single() {1.0f, 2.0f, 3.0f, 4.0f, 5.0f}, 1)>
- <TestCase(New Single() {2.3f, 1.2f, 4.6f, 8.0f, 3.0f}, 1.2f)>
- <TestCase(New Single() {2.3f, 1.2f, 4.6f, 2.6f, 10231.0f, -2.2f, 1.2f, 4.6f, 8.0f, 3.0f}, -2.2f)>
- <TestCase(New Single() {-1.0f, -1.0f}, -1.0f)>
- Public Sub Min_PassedArray_ReturnsMinimumValue(array() As Single, expected As Single)
- Dim actual As Single = Kumite.Min(array)
- Assert.AreEqual(expected, actual)
- End Sub
- End Class
For large numbers, use long. A and b should be Int32/ int
- The built in long type looks sexier and is used more
- A and b should be 32 so we dont go out of range
- Need to type cast one of the ints so that it does long addition and not integer addition which would return and overflow
- Can be static so should be static
- Arrow functions are grim but thats just my opinion
🙌
public static class Sum { public static long GetSum(int a, int b) { return (long)a + b; } }
using System;public class Sum- public static class Sum
- {
public Int64 GetSum(Int64 a, Int64 b) => a + b;- public static long GetSum(int a, int b)
- {
- return (long)a + b;
- }
- }
using NUnit.Framework; [TestFixture] public class SumTests { [TestCase(9, -10, -1)] [TestCase(12, -4, 8)] [TestCase(-16, -100, -116)] [TestCase(62, 38, 100)] public void GetSum_Addition_ReturnsSum(int a, int b, long expected) { long val = Sum.GetSum(a, b); Assert.AreEqual(expected, val, $"{val} should be the addition of a: {a} and b: {b} which is {expected}"); } [TestCase(2147483647, 2147483647, 4294967294)] [TestCase(-2147483647, -2147483647, -4294967294)] public void GetSum_MinMax_ReturnsSumMaxMin(int a, int b, long expected) { long val = Sum.GetSum(a, b); Assert.AreEqual(expected, val, $"{val} should be the addition of a: {a} and b: {b} which is {expected}"); } }
namespace Solution {using NUnit.Framework;using System;- using NUnit.Framework;
[TestFixture]public class SolutionTest- [TestFixture]
- public class SumTests
- {
- [TestCase(9, -10, -1)]
- [TestCase(12, -4, 8)]
- [TestCase(-16, -100, -116)]
- [TestCase(62, 38, 100)]
- public void GetSum_Addition_ReturnsSum(int a, int b, long expected)
- {
[Test]public void MyTest(){Sum sum = new Sum();Assert.AreEqual(19,sum.GetSum(9, 10));Assert.AreEqual(22,sum.GetSum(12,10));Assert.AreEqual(4294967292,sum.GetSum(2147483646,2147483646));}- long val = Sum.GetSum(a, b);
- Assert.AreEqual(expected, val, $"{val} should be the addition of a: {a} and b: {b} which is {expected}");
- }
}- [TestCase(2147483647, 2147483647, 4294967294)]
- [TestCase(-2147483647, -2147483647, -4294967294)]
- public void GetSum_MinMax_ReturnsSumMaxMin(int a, int b, long expected)
- {
- long val = Sum.GetSum(a, b);
- Assert.AreEqual(expected, val, $"{val} should be the addition of a: {a} and b: {b} which is {expected}");
- }
- }
Hello World
A method that returns "Hello World".
Module Kumite
Function HelloWorld()
return "Hello World"
End Function
End Module
Imports NUnit.Framework
<TestFixture>
Public Class AdderTest
<Test>
Public Sub GetsHelloWorld()
Assert.AreEqual("Hello World", Kumite.HelloWorld())
End Sub
End Class