public static void Main()
Case[] cases = new Case[]{
new Case{ amount=1000 , rep=0 } ,
new Case{ amount=1000 , rep=1 } ,
new Case{ amount=1000 , rep=1000 } ,
new Case{ amount=1000 , rep=2000 } ,
new Case{ amount=1000 , rep=3000 } ,
new Case{ amount=1000 , rep=-1 } ,
new Case{ amount=1000 , rep=-1000 } ,
new Case{ amount=1000 , rep=-2000 } ,
new Case{ amount=1000 , rep=-3000 } ,
public int OriginalCode () { return (2 * amount / rep + 1); }
public int Solution1 () { return (2 * amount / Math.Max(rep, 1)); }
public int Solution2 () { return (2 * amount / (Math.Max(rep, 0) + 1)); }
static void RunAllTests ( Case[] cases )
for( int i=0 ; i<cases.Length ; i++ )
Console.WriteLine("amount="+nextCase.amount+" rep="+nextCase.rep);
RunTest( nextCase.OriginalCode , "OriginalCode" );
RunTest( nextCase.Solution1 , "Solution1" );
RunTest( nextCase.Solution2 , "Solution2" );
static void RunTest ( Func<int> testFunc , string testName )
try{ Console.WriteLine("\t "+testName+" = "+testFunc()); }
catch ( System.Exception ex ) { Console.WriteLine("\t "+testName+" throws:"+ex.Message); }