Evaluate() public static méthode

public static Evaluate ( Array, instructions ) : string
instructions Array,
Résultat string
Exemple #1
0
 public void Over_copies_the_second_element_if_there_are_more_than_two()
 {
     Assert.Equal("1 2 3 2", Forth.Evaluate(new[] { "1 2 3 over" }));
 }
Exemple #2
0
 public void Dup_copies_the_top_value_on_the_stack()
 {
     Assert.Equal("1 2 2", Forth.Evaluate(new[] { "1 2 dup" }));
 }
Exemple #3
0
 public void Addition_can_add_two_numbers()
 {
     Assert.Equal("3", Forth.Evaluate(new[] { "1 2 +" }));
 }
Exemple #4
0
 public void Division_errors_if_dividing_by_zero()
 {
     Assert.Throws <DivideByZeroException>(() => Forth.Evaluate(new[] { "4 0 /" }));
 }
Exemple #5
0
 public void Combined_arithmetic_addition_and_subtraction()
 {
     Assert.Equal("-1", Forth.Evaluate(new[] { "1 2 + 4 -" }));
 }
Exemple #6
0
 public void Multiplication_can_multiply_two_numbers()
 {
     Assert.Equal("8", Forth.Evaluate(new[] { "2 4 *" }));
 }
Exemple #7
0
 public void Division_can_divide_two_numbers()
 {
     Assert.Equal("4", Forth.Evaluate(new[] { "12 3 /" }));
 }
Exemple #8
0
 public void User_defined_words_can_use_different_words_with_the_same_name()
 {
     Assert.Equal("5 6", Forth.Evaluate(new[] { ": foo 5 ;", ": bar foo ;", ": foo 6 ;", "bar foo" }));
 }
Exemple #9
0
 public void User_defined_words_can_define_word_that_uses_word_with_the_same_name()
 {
     Assert.Equal("11", Forth.Evaluate(new[] { ": foo 10 ;", ": foo foo 1 + ;", "foo" }));
 }
Exemple #10
0
 public void User_defined_words_can_override_built_in_words()
 {
     Assert.Equal("1 1", Forth.Evaluate(new[] { ": swap dup ;", "1 swap" }));
 }
Exemple #11
0
 public void User_defined_words_can_override_built_in_operators()
 {
     Assert.Equal("12", Forth.Evaluate(new[] { ": + * ;", "3 4 +" }));
 }
Exemple #12
0
 public void User_defined_words_can_override_other_user_defined_words()
 {
     Assert.Equal("1 1 1", Forth.Evaluate(new[] { ": foo dup ;", ": foo dup dup ;", "1 foo" }));
 }
Exemple #13
0
 public void User_defined_words_execute_in_the_right_order()
 {
     Assert.Equal("1 2 3", Forth.Evaluate(new[] { ": countup 1 2 3 ;", "countup" }));
 }
Exemple #14
0
 public void User_defined_words_can_consist_of_built_in_words()
 {
     Assert.Equal("1 1 1", Forth.Evaluate(new[] { ": dup-twice dup dup ;", "1 dup-twice" }));
 }
Exemple #15
0
 public void Case_insensitivity_definitions_are_case_insensitive()
 {
     Assert.Equal("1 1 1 1", Forth.Evaluate(new[] { ": SWAP DUP Dup dup ;", "1 swap" }));
 }
Exemple #16
0
 public void User_defined_words_cannot_redefine_non_negative_numbers()
 {
     Assert.Throws <InvalidOperationException>(() => Forth.Evaluate(new[] { ": 1 2 ;" }));
 }
Exemple #17
0
 public void Subtraction_can_subtract_two_numbers()
 {
     Assert.Equal("-1", Forth.Evaluate(new[] { "3 4 -" }));
 }
Exemple #18
0
 public void User_defined_words_errors_if_executing_a_non_existent_word()
 {
     Assert.Throws <InvalidOperationException>(() => Forth.Evaluate(new[] { "foo" }));
 }
Exemple #19
0
 public void Parsing_and_numbers_numbers_just_get_pushed_onto_the_stack()
 {
     Assert.Equal("1 2 3 4 5", Forth.Evaluate(new[] { "1 2 3 4 5" }));
 }
Exemple #20
0
 public void Case_insensitivity_dup_is_case_insensitive()
 {
     Assert.Equal("1 1 1 1", Forth.Evaluate(new[] { "1 DUP Dup dup" }));
 }
Exemple #21
0
 public void Division_performs_integer_division()
 {
     Assert.Equal("2", Forth.Evaluate(new[] { "8 3 /" }));
 }
Exemple #22
0
 public void Case_insensitivity_drop_is_case_insensitive()
 {
     Assert.Equal("1", Forth.Evaluate(new[] { "1 2 3 4 DROP Drop drop" }));
 }
Exemple #23
0
 public void Division_errors_if_there_is_only_one_value_on_the_stack()
 {
     Assert.Throws <InvalidOperationException>(() => Forth.Evaluate(new[] { "1 /" }));
 }
Exemple #24
0
 public void Case_insensitivity_swap_is_case_insensitive()
 {
     Assert.Equal("2 3 4 1", Forth.Evaluate(new[] { "1 2 SWAP 3 Swap 4 swap" }));
 }
Exemple #25
0
 public void Combined_arithmetic_multiplication_and_division()
 {
     Assert.Equal("2", Forth.Evaluate(new[] { "2 4 * 3 /" }));
 }
Exemple #26
0
 public void Case_insensitivity_over_is_case_insensitive()
 {
     Assert.Equal("1 2 1 2 1", Forth.Evaluate(new[] { "1 2 OVER Over over" }));
 }
Exemple #27
0
 public void Drop_removes_the_top_value_on_the_stack_if_it_is_not_the_only_one()
 {
     Assert.Equal("1", Forth.Evaluate(new[] { "1 2 drop" }));
 }
Exemple #28
0
 public void Case_insensitivity_user_defined_words_are_case_insensitive()
 {
     Assert.Equal("1 1 1 1", Forth.Evaluate(new[] { ": foo dup ;", "1 FOO Foo foo" }));
 }
Exemple #29
0
 public void Drop_errors_if_there_is_nothing_on_the_stack()
 {
     Assert.Throws <InvalidOperationException>(() => Forth.Evaluate(new[] { "drop" }));
 }
Exemple #30
0
 public void Over_copies_the_second_element_if_there_are_only_two()
 {
     Assert.Equal("1 2 1", Forth.Evaluate(new[] { "1 2 over" }));
 }