def test_func_call_multiple_parameters(self): code = """ void main(){printf("number : %d %s", 12, "string 2");} """ target_output = "number : 12 string 2" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_simple_func_call(self): code = """ void main() {printf("hello world");} """ target_output = "hello world" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_multiple_inline_declarations_and_Assignment_different(self): code = """ void main() { int x,y = 3; } """ target_output = "" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_multiple_inline_declarations(self): code = """ void main() { int x,y; } """ target_output = "" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_simple_var_declaration(self): code = """ void main() { int x; } """ target_output = "" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_multiple_inline_declarations_and_Assignment_and_Use(self): code = """ void main() { int x = 2,y = 3; printf("%i %i",x,y); } """ target_output = "2 3" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_single_if_true(self): code = """ void main() { if (1) printf("hello world"); } """ target_output = "hello world" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_precedence(self): code = """ void main(){ printf("1+2*3+4*(1+3)*2 = %d",1+2*3+4*(1+3)*2); } """ target_output = "1+2*3+4*(1+3)*2 = " + str(1 + 2 * 3 + 4 * (1 + 3) * 2) scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_simple_var_Use(self): code = """ void main() { int x = 3; printf("%i",x); } """ target_output = "3" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_simple_var_Assignment(self): code = """ void main() { int x; x = 3; } """ target_output = "" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_double_scopes(self): code = """ void main() { int x = 0; {} } """ target_output = "" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_int_div_multiple_times(self): code = """ void main(){ printf("4//2//2 = %d",4//2//2); } """ target_output = "4//2//2 = " + str(4 // 2 // 2) scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_mul_div(self): code = """ void main(){ printf("5*6//2 = %d",5*6//2); } """ target_output = "5*6//2 = " + str(5 * 6 // 2) scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_mul_multiple_times(self): code = """ void main(){ printf("2*3*13 = %d",2*3*13); } """ target_output = "2*3*13 = " + str(2 * 3 * 13) scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_minus(self): code = """ void main(){ printf("2-1 = %d",2-1); } """ target_output = "2-1 = " + str(2 - 1) scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_plus(self): code = """ void main(){ printf("1+2 = %d",1+2); } """ target_output = "1+2 = " + str(1 + 2) scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_plus_multiple_times(self): code = """ void main(){ printf("1+2+13 = %d",1+2+13); } """ target_output = "1+2+13 = " + str(1 + 2 + 13) scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_nested_if_scope_Access_to_outside_scope(self): code = """ void main() { int x = 99; if(x){ printf("%d",x); } } """ target_output = "99" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_single_not_equal_false(self): code = """ void main(){ printf("begin test "); if(4 != 4){ printf("Hurray"); } printf("end_test"); } """ target_output = "begin test " + "end_test" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_single_less_than_true(self): code = """ void main(){ printf("begin test "); if(4 < 5){ printf("Hurray"); } printf("end_test"); } """ target_output = "begin test " + "Hurray" + "end_test" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_single_if_true_else(self): code = """ void main() { if (1) printf("nominal output"); else printf("bad output"); printf("always printed"); } """ target_output = "nominal output" + "always printed" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_nested_scope_access_to_scope_variables(self): code = """ void main() { int x = 122; { printf("%i",x); } } """ target_output = "122" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_access_to_global_variables(self): code = """ int x; void main() { if(1){ x = 2; printf("%i",x); } } """ target_output = "2" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_variable_assignment_in_inner_scope(self): code = """ void main() { int x = 12; printf("%d ",x); { x = 3; printf("%d ",x); } printf("%d",x); } """ target_output = "12 3 3" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_shadowing(self): code = """ void main() { int x = 1; if(1){ int x = 2; printf("%i",x); } printf("%i",x); } """ target_output = "21" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_single_if_false_else(self): code = """ void main() { if (0) printf("expr is true output"); else printf("expr is false"); printf("always printed"); } """ target_output = "expr is false" + "always printed" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_multiple_not_equal_false(self): code = """ void main(){ printf("begin test "); if(4 != 1){ printf("Hurray"); } if (3 != 5) printf("AKS"); printf("end_test"); } """ target_output = "begin test " + "Hurray" + "AKS" + "end_test" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_chained_if_else_middle_branch(self): code = """ void main() { if (0) printf("first branch"); else if(0) printf("second branch"); else if (1) printf("third branch"); else printf ("fall back branch"); printf("always printed"); } """ target_output = "third branch" + "always printed" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_if_false_else_multiple_statement_body(self): code = """ void main() { if (0){ printf("if print 1"); printf("if print 2"); } else{ printf ("else print 1"); printf ("else print 2"); } printf(" always printed"); } """ target_output = "else print 1" + "else print 2" + " always printed" scc_output = run_code(code) self.assertEquals(target_output, scc_output)
def test_access_of_multiple_scopes(self): code = """ void main() { int z=1; if(1){ int x = 2; printf("%i ",x); } if(1){ int y=7; printf("%i %i",y,z); } } """ target_output = "2 7 1" scc_output = run_code(code) self.assertEquals(target_output, scc_output)