mirror of
https://github.com/cc65/cc65.git
synced 2024-11-19 06:31:31 +00:00
add failing tests in test/todo
This commit is contained in:
parent
c5728626b0
commit
6c5807001b
103
test/todo/float-basic-const-var.c
Normal file
103
test/todo/float-basic-const-var.c
Normal file
@ -0,0 +1,103 @@
|
||||
|
||||
// test basic arithmetic operations
|
||||
// WIP WIP WIP
|
||||
|
||||
#ifdef CONIO
|
||||
#include <conio.h>
|
||||
#define WAIT() cgetc()
|
||||
#else
|
||||
#define WAIT()
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <_float.h>
|
||||
|
||||
float fp1 = 12.34f;
|
||||
float fp2; // non initialized
|
||||
float fp3, fp4 = 55.55f;
|
||||
|
||||
char buf[0x20];
|
||||
char buf2[0x20];
|
||||
char buf3[0x20];
|
||||
|
||||
unsigned long l1,l2;
|
||||
|
||||
signed char var_schar;
|
||||
unsigned char var_uchar;
|
||||
signed int var_sint;
|
||||
unsigned int var_uint;
|
||||
signed long var_slong;
|
||||
unsigned long var_ulong;
|
||||
|
||||
int result = 0;
|
||||
|
||||
// returns 1 if value in f matches the string
|
||||
// the string is a hex value without leading "0x"
|
||||
int compare(float f, char *str)
|
||||
{
|
||||
char temp[12];
|
||||
sprintf(temp, "%08lx", *((uint32_t*)&f));
|
||||
return (strcmp(temp, str) == 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
void test1(float f, char *str)
|
||||
{
|
||||
if (compare(f, str)) {
|
||||
// printf(" (ok)");
|
||||
printf("\n");
|
||||
} else {
|
||||
printf(" (failed) !!!\n");
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
// when making sub tests work, remove them here and uncomment them in val/float-basic.c
|
||||
void constvar(void)
|
||||
{
|
||||
printf("\nconstant vs variable\n\n");
|
||||
|
||||
/* addition, constant + variable */
|
||||
fp2 = 43.21f;
|
||||
fp3 = 12.7f + fp2; // FIXME: wrong, the add is dropped?
|
||||
printf("addition: %s+%s=%s\n", _ftostr(buf, 12.7f), _ftostr(buf2, fp2), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x425fa3d7] %s", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
test1(fp3, "425fa3d7");
|
||||
|
||||
/* substraction, constant - variable */
|
||||
fp2 = 12.34;
|
||||
fp3 = 11.5f - fp2; // FIXME: wrong, fp2 appears to become 0?
|
||||
printf("substraction: %s-%s=%s\n", _ftostr(buf, 11.5f), _ftostr(buf2, fp2), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0xbf570a40] %s ()", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
test1(fp3, "bf570a40");
|
||||
|
||||
fp2 = 2.3f;
|
||||
fp3 = 25.2f * fp2; // FIXME: wrong, fp3 appears to become 0?
|
||||
printf("multiplication: %s*%s=%s\n", _ftostr(buf, 25.2f), _ftostr(buf2, fp2), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x4267d70a] %s ()", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
test1(fp3, "4267d70a");
|
||||
|
||||
fp2 = 2.3f;
|
||||
fp3 = 25.2f / fp2;
|
||||
printf("division: %s/%s=%s\n", _ftostr(buf, 25.2f), _ftostr(buf2, fp2), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x412f4dea] %s ()", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
test1(fp3, "412f4dea");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
float fp2 = 43.21f;
|
||||
|
||||
printf("float-basic-const-var\n");
|
||||
printf("fp1:0x%08lx [0x414570a4] %s (12.340000)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
|
||||
printf("fp2:0x%08lx [0x422cd70a] %s (43.209999)\n", *((uint32_t*)&fp2), _ftostr(buf, fp2));
|
||||
|
||||
constvar();
|
||||
WAIT();
|
||||
|
||||
printf("\nfloat-basic-const-var (res:%d)\n", result);
|
||||
return result;
|
||||
}
|
106
test/todo/float-basic-var-const.c
Normal file
106
test/todo/float-basic-var-const.c
Normal file
@ -0,0 +1,106 @@
|
||||
|
||||
// test basic arithmetic operations
|
||||
// WIP WIP WIP
|
||||
|
||||
#ifdef CONIO
|
||||
#include <conio.h>
|
||||
#define WAIT() cgetc()
|
||||
#else
|
||||
#define WAIT()
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <_float.h>
|
||||
|
||||
float fp1 = 12.34f;
|
||||
float fp2; // non initialized
|
||||
float fp3, fp4 = 55.55f;
|
||||
|
||||
char buf[0x20];
|
||||
char buf2[0x20];
|
||||
char buf3[0x20];
|
||||
|
||||
unsigned long l1,l2;
|
||||
|
||||
signed char var_schar;
|
||||
unsigned char var_uchar;
|
||||
signed int var_sint;
|
||||
unsigned int var_uint;
|
||||
signed long var_slong;
|
||||
unsigned long var_ulong;
|
||||
|
||||
int result = 0;
|
||||
|
||||
// returns 1 if value in f matches the string
|
||||
// the string is a hex value without leading "0x"
|
||||
int compare(float f, char *str)
|
||||
{
|
||||
char temp[12];
|
||||
sprintf(temp, "%08lx", *((uint32_t*)&f));
|
||||
return (strcmp(temp, str) == 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
void test1(float f, char *str)
|
||||
{
|
||||
if (compare(f, str)) {
|
||||
// printf(" (ok)");
|
||||
printf("\n");
|
||||
} else {
|
||||
printf(" (failed) !!!\n");
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
// when making sub tests work, remove them here and uncomment them in val/float-basic.c
|
||||
void varconst(void)
|
||||
{
|
||||
printf("\nvariable vs constant\n\n");
|
||||
/* addition, variable + constant */
|
||||
fp1 = 55.549999f;
|
||||
fp3 = fp1 + 0.05f;
|
||||
printf("addition: %s+%s=%s\n", _ftostr(buf, fp3), _ftostr(buf3, 0.05f), _ftostr(buf2, fp1));
|
||||
printf(" fp3:0x%08lx [0x425e6666] %s", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
test1(fp3, "425e6666");
|
||||
|
||||
#if 0
|
||||
/* substraction, variable - constant */
|
||||
fp1 = 12.34;
|
||||
fp3 = fp1 - 11.5f; // FIXME: Invalid operands for binary operator '-'
|
||||
printf("substraction: %s-%s=%s\n", _ftostr(buf, fp1), _ftostr(buf2, 11.5f), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x3f570a40] %s ()", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
test1(fp3, "3f570a40");
|
||||
#endif
|
||||
|
||||
fp1 = 25.2f;
|
||||
fp3 = fp1 * 2.3f;
|
||||
printf("multiplication: %s*%s=%s\n", _ftostr(buf, fp1), _ftostr(buf2, 2.3f), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x4267d70a] %s ()", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
test1(fp3, "4267d70a");
|
||||
|
||||
#if 0
|
||||
fp1 = 25.2f;
|
||||
fp3 = fp1 / 2.3f; // FIXME: division by zero
|
||||
printf("division: %s/%s=%s\n", _ftostr(buf, fp1), _ftostr(buf2, 2.3f), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x412f4dea] %s ()", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
test1(fp3, "412f4dea");
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
float fp2 = 43.21f;
|
||||
|
||||
printf("float-basic-var-const\n");
|
||||
printf("fp1:0x%08lx [0x414570a4] %s (12.340000)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
|
||||
printf("fp2:0x%08lx [0x422cd70a] %s (43.209999)\n", *((uint32_t*)&fp2), _ftostr(buf, fp2));
|
||||
|
||||
varconst();
|
||||
WAIT();
|
||||
|
||||
printf("\nfloat-basic-var-const (res:%d)\n", result);
|
||||
return result;
|
||||
}
|
106
test/todo/float-basic-var-var.c
Normal file
106
test/todo/float-basic-var-var.c
Normal file
@ -0,0 +1,106 @@
|
||||
|
||||
// test basic arithmetic operations
|
||||
// WIP WIP WIP
|
||||
|
||||
#ifdef CONIO
|
||||
#include <conio.h>
|
||||
#define WAIT() cgetc()
|
||||
#else
|
||||
#define WAIT()
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <_float.h>
|
||||
|
||||
float fp1 = 12.34f;
|
||||
float fp2; // non initialized
|
||||
float fp3, fp4 = 55.55f;
|
||||
|
||||
char buf[0x20];
|
||||
char buf2[0x20];
|
||||
char buf3[0x20];
|
||||
|
||||
unsigned long l1,l2;
|
||||
|
||||
signed char var_schar;
|
||||
unsigned char var_uchar;
|
||||
signed int var_sint;
|
||||
unsigned int var_uint;
|
||||
signed long var_slong;
|
||||
unsigned long var_ulong;
|
||||
|
||||
int result = 0;
|
||||
|
||||
// returns 1 if value in f matches the string
|
||||
// the string is a hex value without leading "0x"
|
||||
int compare(float f, char *str)
|
||||
{
|
||||
char temp[12];
|
||||
sprintf(temp, "%08lx", *((uint32_t*)&f));
|
||||
return (strcmp(temp, str) == 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
void test1(float f, char *str)
|
||||
{
|
||||
if (compare(f, str)) {
|
||||
// printf(" (ok)");
|
||||
printf("\n");
|
||||
} else {
|
||||
printf(" (failed) !!!\n");
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
// when making sub tests work, remove them here and uncomment them in val/float-basic.c
|
||||
void varvar(void)
|
||||
{
|
||||
printf("\nvariable vs variable\n\n");
|
||||
|
||||
/* addition, variable + variable */
|
||||
fp1 = 12.34f;
|
||||
fp2 = 43.21f;
|
||||
fp3 = fp1 + fp2; // = 55.55f
|
||||
printf("addition: %s+%s=%s\n", _ftostr(buf, fp1), _ftostr(buf2, fp2), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x425e3333] %s (exp:55.549999)", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
test1(fp3, "425e3333");
|
||||
|
||||
/* substraction, variable - variable */
|
||||
fp3 = fp1 - fp2;
|
||||
printf("substraction: %s-%s=%s\n", _ftostr(buf, fp1), _ftostr(buf2, fp2), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0xc1f6f5c2] %s (exp:-30.869999)", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
test1(fp3, "c1f6f5c2");
|
||||
|
||||
fp1 = 25.2f;
|
||||
fp2 = 2.3f;
|
||||
fp3 = fp1 * fp2;
|
||||
printf("multiplication: %s*%s=%s\n", _ftostr(buf, fp1), _ftostr(buf2, fp2), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x4267d70a] %s (exp:57.96)", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
test1(fp3, "4267d70a");
|
||||
|
||||
fp1 = 25.2f;
|
||||
fp2 = 2.5f;
|
||||
fp3 = fp1 / fp2;
|
||||
printf("division: %s/%s=%s\n", _ftostr(buf, fp1), _ftostr(buf2, fp2), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x412147ae] %s (exp:10.08)", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
test1(fp3, "412147ae");
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
float fp2 = 43.21f;
|
||||
|
||||
printf("float-basic-var-var\n");
|
||||
printf("fp1:0x%08lx [0x414570a4] %s (12.340000)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
|
||||
printf("fp2:0x%08lx [0x422cd70a] %s (43.209999)\n", *((uint32_t*)&fp2), _ftostr(buf, fp2));
|
||||
|
||||
varvar();
|
||||
WAIT();
|
||||
|
||||
printf("\nfloat-basic-var-var (res:%d)\n", result);
|
||||
return result;
|
||||
}
|
75
test/todo/float-cmp-const-const.c
Normal file
75
test/todo/float-cmp-const-const.c
Normal file
@ -0,0 +1,75 @@
|
||||
|
||||
// test comparison operations
|
||||
// WIP WIP WIP
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <_float.h>
|
||||
|
||||
#ifdef CONIO
|
||||
#include <conio.h>
|
||||
#define WAIT() cgetc()
|
||||
#else
|
||||
#define WAIT()
|
||||
#endif
|
||||
|
||||
float fp1, fp2, fp3, fp4;
|
||||
|
||||
char buf[0x30];
|
||||
char buf2[0x30];
|
||||
char buf3[0x30];
|
||||
|
||||
signed char var_schar;
|
||||
unsigned char var_uchar;
|
||||
signed int var_sint;
|
||||
unsigned int var_uint;
|
||||
signed long var_slong;
|
||||
unsigned long var_ulong;
|
||||
|
||||
int result = 0;
|
||||
|
||||
#define expect(msg, exp, val) \
|
||||
printf("%s %s%s\n", \
|
||||
msg, \
|
||||
val ? "true" : "false", \
|
||||
(exp != val) ? " (failed)" : ""); \
|
||||
if (exp != val) { \
|
||||
result++; \
|
||||
}
|
||||
|
||||
// when making individual sub tests work, remove them here and uncomment them
|
||||
// in val/float-cmp.c
|
||||
void constconst(void)
|
||||
{
|
||||
//-------------------------------------------------------------------------
|
||||
// float constant vs float const
|
||||
printf("const vs const\n");
|
||||
|
||||
expect("1.5f == 1.6f is", 0, (1.5f == 1.6f));
|
||||
expect("1.6f == 1.5f is", 0, (1.6f == 1.5f));
|
||||
|
||||
expect("1.5f != 1.6f is", 1, (1.5f != 1.6f));
|
||||
expect("1.6f != 1.5f is", 1, (1.6f != 1.5f));
|
||||
|
||||
expect("1.5f < 1.6f is", 1, (1.5f < 1.6f));
|
||||
|
||||
expect("1.6f > 1.5f is", 1, (1.6f > 1.5f));
|
||||
|
||||
expect("1.6f <= 1.5f is", 0, (1.6f <= 1.5f));
|
||||
|
||||
expect("1.5f >= 1.6f is", 0, (1.5f >= 1.6f));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("float-cmp-const-const\n");
|
||||
|
||||
constconst();
|
||||
|
||||
printf("float-cmp-const-const (res: %d)\n", result);
|
||||
return result;
|
||||
}
|
86
test/todo/float-cmp-const-var.c
Normal file
86
test/todo/float-cmp-const-var.c
Normal file
@ -0,0 +1,86 @@
|
||||
|
||||
// test comparison operations
|
||||
// WIP WIP WIP
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <_float.h>
|
||||
|
||||
#ifdef CONIO
|
||||
#include <conio.h>
|
||||
#define WAIT() cgetc()
|
||||
#else
|
||||
#define WAIT()
|
||||
#endif
|
||||
|
||||
float fp1, fp2, fp3, fp4;
|
||||
|
||||
char buf[0x30];
|
||||
char buf2[0x30];
|
||||
char buf3[0x30];
|
||||
|
||||
signed char var_schar;
|
||||
unsigned char var_uchar;
|
||||
signed int var_sint;
|
||||
unsigned int var_uint;
|
||||
signed long var_slong;
|
||||
unsigned long var_ulong;
|
||||
|
||||
int result = 0;
|
||||
|
||||
#define expect(msg, exp, val) \
|
||||
printf("%s %s%s\n", \
|
||||
msg, \
|
||||
val ? "true" : "false", \
|
||||
(exp != val) ? " (failed)" : ""); \
|
||||
if (exp != val) { \
|
||||
result++; \
|
||||
}
|
||||
|
||||
// float constant vs float variable
|
||||
// when making individual sub tests work, remove them here and uncomment them
|
||||
// in val/float-cmp.c
|
||||
void constvar(void)
|
||||
{
|
||||
printf("const vs var\n");
|
||||
|
||||
expect("1.5f == 1.6f is", 0, (1.5f == fp1));
|
||||
expect("1.6f == 1.5f is", 0, (1.6f == fp2));
|
||||
expect("1.6f == 1.6f is", 1, (1.6f == fp1));
|
||||
|
||||
expect("1.5f != 1.6f is", 1, (1.5f != fp1));
|
||||
expect("1.6f != 1.5f is", 1, (1.6f != fp2));
|
||||
expect("1.6f != 1.6f is", 0, (1.6f != fp1));
|
||||
|
||||
expect("1.5f < 1.6f is", 1, (1.5f < fp1));
|
||||
expect("1.6f < 1.5f is", 0, (1.6f < fp2));
|
||||
expect("1.6f < 1.6f is", 0, (1.6f < fp1));
|
||||
|
||||
expect("1.5f > 1.6f is", 0, (1.5f > fp1));
|
||||
expect("1.6f > 1.5f is", 1, (1.6f > fp2));
|
||||
expect("1.6f > 1.6f is", 0, (1.6f > fp1));
|
||||
|
||||
expect("1.5f <= 1.6f is", 1, (1.5f <= fp1));
|
||||
expect("1.6f <= 1.5f is", 0, (1.6f <= fp2));
|
||||
expect("1.6f <= 1.6f is", 1, (1.6f <= fp1));
|
||||
|
||||
expect("1.5f >= 1.6f is", 0, (1.5f >= fp1));
|
||||
expect("1.6f >= 1.5f is", 1, (1.6f >= fp2));
|
||||
expect("1.6f >= 1.6f is", 1, (1.6f >= fp1));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("float-cmp-const-var\n");
|
||||
|
||||
fp1 = 1.6f;
|
||||
fp2 = 1.5f;
|
||||
constvar();
|
||||
|
||||
printf("float-cmp-const-var (res: %d)\n", result);
|
||||
return result;
|
||||
}
|
78
test/todo/float-cmp-var-const.c
Normal file
78
test/todo/float-cmp-var-const.c
Normal file
@ -0,0 +1,78 @@
|
||||
|
||||
// test comparison operations
|
||||
// WIP WIP WIP
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <_float.h>
|
||||
|
||||
#ifdef CONIO
|
||||
#include <conio.h>
|
||||
#define WAIT() cgetc()
|
||||
#else
|
||||
#define WAIT()
|
||||
#endif
|
||||
|
||||
float fp1, fp2, fp3, fp4;
|
||||
|
||||
char buf[0x30];
|
||||
char buf2[0x30];
|
||||
char buf3[0x30];
|
||||
|
||||
signed char var_schar;
|
||||
unsigned char var_uchar;
|
||||
signed int var_sint;
|
||||
unsigned int var_uint;
|
||||
signed long var_slong;
|
||||
unsigned long var_ulong;
|
||||
|
||||
int result = 0;
|
||||
|
||||
#define expect(msg, exp, val) \
|
||||
printf("%s %s%s\n", \
|
||||
msg, \
|
||||
val ? "true" : "false", \
|
||||
(exp != val) ? " (failed)" : ""); \
|
||||
if (exp != val) { \
|
||||
result++; \
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// float variable vs float constant
|
||||
|
||||
// when making individual sub tests work, remove them here and uncomment them
|
||||
// in val/float-cmp.c
|
||||
void varconst(void)
|
||||
{
|
||||
printf("var vs const\n");
|
||||
|
||||
fp1 = 1.6f;
|
||||
fp2 = 1.5f;
|
||||
|
||||
expect("1.6f == 1.6f is", 1, (fp1 == 1.6f));
|
||||
|
||||
expect("1.6f != 1.6f is", 0, (fp1 != 1.6f));
|
||||
|
||||
expect("1.5f < 1.6f is", 1, (fp2 < 1.6f));
|
||||
|
||||
expect("1.5f > 1.6f is", 0, (fp2 > 1.6f));
|
||||
expect("1.6f > 1.6f is", 0, (fp1 > 1.6f));
|
||||
|
||||
expect("1.5f <= 1.6f is", 1, (fp2 <= 1.6f));
|
||||
expect("1.6f <= 1.6f is", 1, (fp1 <= 1.6f));
|
||||
|
||||
expect("1.5f >= 1.6f is", 0, (fp2 >= 1.6f));
|
||||
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("float-cmp-var-const\n");
|
||||
|
||||
varconst();
|
||||
|
||||
printf("float-cmp-var-const (res: %d)\n", result);
|
||||
return result;
|
||||
}
|
Loading…
Reference in New Issue
Block a user