calculator_test.gno

2.39 Kb ยท 111 lines
  1package calculator
  2
  3import "testing"
  4
  5func Test_Addition(t *testing.T) {
  6	// Increment the value
  7	value := ComputeResult("1+1")
  8	// Verify the value is equal to 2
  9	if value != "2" {
 10		t.Fatalf("1 + 1 is not equal to 2")
 11	}
 12}
 13
 14func Test_Subtraction(t *testing.T) {
 15	// Increment the value
 16	value := ComputeResult("1-1")
 17	// Verify the value is equal to 0
 18	if value != "0" {
 19		t.Fatalf("1 - 1 is not equal to 0")
 20	}
 21}
 22
 23func Test_Multiplication(t *testing.T) {
 24	// Increment the value
 25	value := ComputeResult("1*4")
 26	// Verify the value is equal to 4
 27	if value != "4" {
 28		t.Fatalf("1 * 4 is not equal to 4")
 29	}
 30}
 31
 32func Test_Division(t *testing.T) {
 33	// Increment the value
 34	value := ComputeResult("4/2")
 35	// Verify the value is equal to 2
 36	if value != "2" {
 37		t.Fatalf("4 / 2 is not equal to 2")
 38	}
 39}
 40
 41func Test_AdditionDecimal(t *testing.T) {
 42	// Increment the value
 43	value := ComputeResult("1.2+1.3")
 44	// Verify the value is equal to 2.5
 45	if value != "2.5" {
 46		t.Fatalf("1.2 + 1.3 is not equal to 2.5")
 47	}
 48}
 49
 50func Test_SubtractionDecimal(t *testing.T) {
 51	// Increment the value
 52	value := ComputeResult("1.3-1.2")
 53	// Verify the value is equal to 0.1
 54	if value != "0.1" {
 55		t.Fatalf("1.3 - 1.2 is not equal to 0.1")
 56	}
 57}
 58
 59func Test_MultiplicationDecimal(t *testing.T) {
 60	// Increment the value
 61	value := ComputeResult("3*1.5")
 62	// Verify the value is equal to 4.5
 63	if value != "4.5" {
 64		t.Fatalf("3 * 1.5 is not equal to 4.5")
 65	}
 66}
 67
 68func Test_DivisionDecimal(t *testing.T) {
 69	// Increment the value
 70	value := ComputeResult("2/0.5")
 71	// Verify the value is equal to 4
 72	if value != "4" {
 73		t.Fatalf("2 / 0.5 is not equal to 4")
 74	}
 75}
 76
 77func Test_BaseParenthesis(t *testing.T) {
 78	// Increment the value
 79	value := ComputeResult("2*(3+4)")
 80	// Verify the value is equal to 14
 81	if value != "14" {
 82		t.Fatalf("2 * (3 + 4) is not equal to 14")
 83	}
 84}
 85
 86func Test_AdvancedParenthesis(t *testing.T) {
 87	// Increment the value
 88	value := ComputeResult("2*(3+4/(6-2))")
 89	// Verify the value is equal to 8
 90	if value != "8" {
 91		t.Fatalf("2 * (3 + 4 / (6 - 2)) is not equal to 8")
 92	}
 93}
 94
 95func Test_Negative(t *testing.T) {
 96	// Increment the value
 97	value := ComputeResult("-2+10")
 98	// Verify the value is equal to 8
 99	if value != "8" {
100		t.Fatalf("-2 + 10 is not equal to 8")
101	}
102}
103
104func Test_Negative2(t *testing.T) {
105	// Increment the value
106	value := ComputeResult("-2*-10")
107	// Verify the value is equal to 20
108	if value != "20" {
109		t.Fatalf("-2 * -10 is not equal to 20")
110	}
111}