Skip to content

Instantly share code, notes, and snippets.

@HoraceBury
Created April 4, 2018 12:54
Show Gist options
  • Save HoraceBury/d8c5a7a0fa77780a1988815fd2b56203 to your computer and use it in GitHub Desktop.
Save HoraceBury/d8c5a7a0fa77780a1988815fd2b56203 to your computer and use it in GitHub Desktop.
Executing an equation in C# proven with nUnit.
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