for loop
public class Program {
public static int loop(int repeat){
int result = 0;
for(String s = ""; s.length() < repeat; s += " ") {
result = s.length();
}
return Integer.parseInt(new Integer(result).toString().trim());
}
}
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
// TODO: Replace examples and use TDD by writing your own tests
class SolutionTest {
@Test
void testSomething() {
assertEquals(9, Program.loop(10));
}
}
Somebody optimize my not so great code.
using System.Linq;
public class Program{
public static int ToInt(string s){
int result = 0;
foreach(char c in s){
result *= 10;
result += "abcdefghijklmnopqrstuvwxyz".IndexOf(c)+1;
}
return result;
}
}
namespace Solution {
using NUnit.Framework;
using System;
using System.Linq;
// TODO: Replace examples and use TDD by writing your own tests
[TestFixture]
public class SolutionTest
{
[Test]
public void MyTest()
{
Assert.AreEqual(12, Program.ToInt("ab"));
}
}
}
This is totally a very complex program.
public class TwoDimensionalArray{
public static T[,] MakeArray<T>(){
return new T[0,0];
}
}
namespace Solution {
using NUnit.Framework;
using System;
// TODO: Replace examples and use TDD by writing your own tests
[TestFixture]
public class SolutionTest
{
[Test]
public void MyTest()
{
Assert.AreEqual(new object[0,0], TwoDimensionalArray.MakeArray<object>());
}
}
}
public class Program
{
public static int GetValue(int i)
{
return i;
}
}
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
// TODO: Replace examples and use TDD by writing your own tests
class SolutionTest {
@Test
void testSomething() {
Program.GetValue(10);
}
}