mirror of
https://github.com/louisrubet/rpn
synced 2024-12-29 10:23:59 +01:00
Add test commands: and, or, xor, not, same
This commit is contained in:
parent
f1c6e4cb4c
commit
7cc5cb19cc
2 changed files with 48 additions and 0 deletions
|
@ -31,6 +31,11 @@ program::keyword_t program::_keywords[] =
|
|||
{ cmd_keyword, "<=", &program::inf_eq, "binary operator <=" },
|
||||
{ cmd_keyword, "!=", &program::diff, "binary operator != (different)" },
|
||||
{ cmd_keyword, "==", &program::eq , "binary operator == (equal)" },
|
||||
{ cmd_keyword, "and", &program::test_and , "boolean operator and" },
|
||||
{ cmd_keyword, "or", &program::test_or , "boolean operator or" },
|
||||
{ cmd_keyword, "xor", &program::test_xor , "boolean operator xor" },
|
||||
{ cmd_keyword, "not", &program::test_not , "boolean operator not" },
|
||||
{ cmd_keyword, "same", &program::same , "boolean operator same (equal)" },
|
||||
|
||||
//STACK
|
||||
{ cmd_undef, "", NULL, "\nSTACK"},
|
||||
|
|
|
@ -83,3 +83,46 @@ void eq(void)
|
|||
putf(0);
|
||||
}
|
||||
}
|
||||
|
||||
void test_and(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
ARG_IS_OF_TYPE(0, cmd_number);
|
||||
ARG_IS_OF_TYPE(1, cmd_number);
|
||||
|
||||
putf((getf() != 0) && (getf() != 0));
|
||||
}
|
||||
|
||||
void test_or(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
ARG_IS_OF_TYPE(0, cmd_number);
|
||||
ARG_IS_OF_TYPE(1, cmd_number);
|
||||
|
||||
putf((getf() != 0) || (getf() != 0));
|
||||
}
|
||||
|
||||
void test_xor(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
ARG_IS_OF_TYPE(0, cmd_number);
|
||||
ARG_IS_OF_TYPE(1, cmd_number);
|
||||
|
||||
floating_t first = getf();
|
||||
floating_t second = getf();
|
||||
putf(((first == 0) && (second != 0)) || ((first != 0) && (second == 0)));
|
||||
}
|
||||
|
||||
void test_not(void)
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_IS_OF_TYPE(0, cmd_number);
|
||||
|
||||
floating_t first = getf();
|
||||
putf((first == 0) ? 1 : 0);
|
||||
}
|
||||
|
||||
void same(void)
|
||||
{
|
||||
eq();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue