views:

20

answers:

2

This may be a strange question and have no answer but I thought I would post it to see how you would go about doing it. I have a line of code:

Grade = Math.Round((Math.Abs(CorrectAnswers) / TotalQuestions) * 100)

Basically that line just figures out the grade no major code work there, what I want to do is execute that specific line with different variables without running the whole application and navigating to the point in the application which for this segment would be completing a 150 question exam, or coding some #temp page and running it from there.

I am trying to track a bug in the code that happens very rarely (you know when the planets in the universe are out of cosmic alignment) and I think my issue lies with this subset and I am trying to find a better/easier way of testing it.

+1  A: 

You could extract this into a method, that takes the values needed as parameters, then create a test harness to execute it.

Mitchel Sellers
A: 

So there are 150 questions, and they can either be right or wrong? Which means there are only 151 possible inputs? Why not just calculate them all? Run this in a console application and see whether you like the results.

  Sub Main()
    Dim Grade As Integer
    Const TotalQuestions = 150
    Console.WriteLine("Marks             Grade")
    For CorrectAnswers = 0 To 150
      Grade = Math.Round((Math.Abs(CorrectAnswers) / TotalQuestions) * 100)
      Console.WriteLine(Format(CorrectAnswers, "000") & " out of 150 => " & _
                         Format(Grade, "000"))
    Next CorrectAnswers
    Console.ReadLine()
  End Sub

Be aware that Math.Round uses banker's rounding by default. If the fractional component of a is halfway between two integers, one of which is even and the other odd, then the even number is returned. You can change this behaviour.

MarkJ