Created
April 4, 2018 12:54
-
-
Save HoraceBury/d8c5a7a0fa77780a1988815fd2b56203 to your computer and use it in GitHub Desktop.
Executing an equation in C# proven with nUnit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using NUnit.Framework; | |
using System.Data; | |
namespace RandomTests | |
{ | |
[TestFixture] | |
public class NumberTests | |
{ | |
public static void Main(string[] args) | |
{ | |
} | |
[Test] | |
public void ComputeTrick() | |
{ | |
var intAnswer = 4 + 4 * 3 - 1 / 3; | |
var intResult = Convert.ToInt32(new DataTable().Compute("4 + 4 * 3 - 1 / 3", null)); | |
var dblAnswer = 4 + 4 * 3 - 1 / 3.0; | |
var dblResult = Convert.ToDouble(new DataTable().Compute("4 + 4 * 3 - 1 / 3", null)); | |
Assert.That(intResult, Is.EqualTo(intAnswer)); | |
Assert.That(dblResult, Is.EqualTo(dblAnswer)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment