initial commit
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
#include "ambiguousoverload.h"
|
||||
|
||||
/**
|
||||
* Regression test for function pointers in aggregate initialisers.
|
||||
*
|
||||
* This setup function must be in a different translation unit from clearView's definition and
|
||||
* direct call (ambiguousoverload_trigger.c). The bug reused clearView's function declaration as an
|
||||
* aggregate-initialiser list node and corrupted its overload chain. Parsing the definition in the
|
||||
* other translation unit then made the otherwise unambiguous direct call fail.
|
||||
*
|
||||
* Holder reproduces the original ambiguous-overload diagnostic. The single-member CallbackHolder
|
||||
* also covers the related initialiser-builder assertion. Both callbacks are invoked to verify that
|
||||
* their aggregate initialisers contain the correct function address. The pragma in
|
||||
* ambiguousoverload.h schedules the companion translation unit so this remains one autotest target.
|
||||
*/
|
||||
void setup(void)
|
||||
{
|
||||
struct Holder holder = { .value = 1, .callback = clearView };
|
||||
struct CallbackHolder callbackHolder = { .callback = clearView };
|
||||
holder.callback();
|
||||
callbackHolder.callback();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
typedef void (*Callback)(void);
|
||||
|
||||
struct Holder
|
||||
{
|
||||
int value;
|
||||
Callback callback;
|
||||
};
|
||||
|
||||
struct CallbackHolder
|
||||
{
|
||||
Callback callback;
|
||||
};
|
||||
|
||||
void clearView(void);
|
||||
|
||||
extern int clearViewCalls;
|
||||
|
||||
#pragma compile("ambiguousoverload_trigger.c")
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "ambiguousoverload.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
void setup(void);
|
||||
|
||||
int clearViewCalls = 0;
|
||||
|
||||
// Kept in this companion translation unit to exercise cross-unit merging.
|
||||
void clearView(void)
|
||||
{
|
||||
clearViewCalls++;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
setup();
|
||||
assert(clearViewCalls == 2);
|
||||
// This direct call was incorrectly diagnosed as an ambiguous overload.
|
||||
clearView();
|
||||
assert(clearViewCalls == 3);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include <assert.h>
|
||||
|
||||
template<int n, int m>
|
||||
void checkmul(void)
|
||||
{
|
||||
__striped static const unsigned r[256] = {
|
||||
#for(i, 256) i * n,
|
||||
};
|
||||
|
||||
for(unsigned i=0; i<m; i++)
|
||||
{
|
||||
assert((i & ~0) * n == r[i]);
|
||||
assert((i & ~1) * n == r[i >> 1] << 1);
|
||||
assert((i & ~3) * n == r[i >> 2] << 2);
|
||||
assert((i & ~7) * n == r[i >> 3] << 3);
|
||||
assert((i & ~15) * n == r[i >> 4] << 4);
|
||||
}
|
||||
for(unsigned i=0; i<256; i++)
|
||||
{
|
||||
assert((i & ~0) * n == r[i]);
|
||||
assert((i & ~1) * n == r[i >> 1] << 1);
|
||||
assert((i & ~3) * n == r[i >> 2] << 2);
|
||||
assert((i & ~7) * n == r[i >> 3] << 3);
|
||||
assert((i & ~15) * n == r[i >> 4] << 4);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
checkmul<3, 170>();
|
||||
checkmul<4, 128>();
|
||||
checkmul<5, 204>();
|
||||
checkmul<6, 170>();
|
||||
checkmul<7, 128>();
|
||||
checkmul<8, 64>();
|
||||
checkmul<9, 170>();
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
#include <assert.h>
|
||||
|
||||
char a2[20][10] = {
|
||||
#for(i, 200) i,
|
||||
};
|
||||
|
||||
int sumrow(char y)
|
||||
{
|
||||
int s = 0;
|
||||
for(char i=0; i<10; i++)
|
||||
s += a2[y][i];
|
||||
return s;
|
||||
}
|
||||
|
||||
int sumrowp5(char y)
|
||||
{
|
||||
int s = 0;
|
||||
for(char i=0; i<10; i++)
|
||||
s += a2[y + 5][i];
|
||||
return s;
|
||||
}
|
||||
|
||||
int sumrowm5(char y)
|
||||
{
|
||||
int s = 0;
|
||||
for(char i=0; i<10; i++)
|
||||
s += a2[y - 5][i];
|
||||
return s;
|
||||
}
|
||||
|
||||
char pick(char y, char x)
|
||||
{
|
||||
return a2[y][x];
|
||||
}
|
||||
|
||||
char pickp5(char y, char x)
|
||||
{
|
||||
return a2[y + 5][x];
|
||||
}
|
||||
|
||||
char pickm5(char y, char x)
|
||||
{
|
||||
return a2[y - 5][x];
|
||||
}
|
||||
|
||||
char pickm50(char y, char x)
|
||||
{
|
||||
return a2[y - 50][x];
|
||||
}
|
||||
|
||||
char pickp50(signed char y, char x)
|
||||
{
|
||||
return a2[y + 50][x];
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for(char i=0; i<15; i++)
|
||||
{
|
||||
assert(sumrow(i) == sumrowm5(i + 5));
|
||||
assert(sumrow(i + 5) == sumrowp5(i));
|
||||
|
||||
for(char j=0; j<10; j++)
|
||||
{
|
||||
assert(pick(i, j) == pickm5(i + 5, j));
|
||||
assert(pick(i + 5, j) == pickp5(i, j));
|
||||
assert(pick(i, j) == pickm50(i + 50, j));
|
||||
assert(pick(i, j) == pickp50(i - 50, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
char s[25][41] = {"Q QQ QQQQQ QQQQQQQQQQQQQ",
|
||||
" QQQQQQQQQQQQQQQQQQQQQQQQQQ",
|
||||
"QQQQQQQQ",
|
||||
" QQQQQQQQQQQQQQQQQ",
|
||||
"QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
|
||||
"QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
" QQQQQQQQQQQQQQQQQQQQQQQQ",
|
||||
"QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
|
||||
"QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
|
||||
"QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
|
||||
"QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
|
||||
"QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
|
||||
"QQQQQQQQQ",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
" QQQQQQQQQQQQQQ"};
|
||||
|
||||
int main()
|
||||
{
|
||||
int i=0, sum = 0;
|
||||
for (unsigned char i = 0; i < 25; i++)
|
||||
{
|
||||
int j = 0;
|
||||
while (s[i][j])
|
||||
{
|
||||
sum += s[i][j] & 3;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
assert(sum == 391);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
#include <assert.h>
|
||||
|
||||
int t, n, m, k;
|
||||
|
||||
struct C1
|
||||
{
|
||||
int a;
|
||||
|
||||
C1(void);
|
||||
~C1(void);
|
||||
C1(const C1 & c);
|
||||
C1 & operator=(const C1 & c);
|
||||
};
|
||||
|
||||
struct C2
|
||||
{
|
||||
C1 nc[10], mc[20];
|
||||
};
|
||||
|
||||
C1::C1(void)
|
||||
{
|
||||
a = 1;
|
||||
n++;
|
||||
t++;
|
||||
}
|
||||
|
||||
C1::C1(const C1 & c)
|
||||
{
|
||||
a = c.a;
|
||||
k++;
|
||||
t++;
|
||||
}
|
||||
|
||||
C1 & C1::operator=(const C1 & c)
|
||||
{
|
||||
a = c.a;
|
||||
m++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
C1::~C1(void)
|
||||
{
|
||||
t--;
|
||||
}
|
||||
|
||||
void test_local_init(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C1 c[10];
|
||||
}
|
||||
|
||||
assert(n == 10 && t == 0);
|
||||
}
|
||||
|
||||
void test_member_init(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C2 d;
|
||||
}
|
||||
|
||||
assert(n == 30 && t == 0);
|
||||
}
|
||||
|
||||
void test_member_array_init(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C2 d[5];
|
||||
}
|
||||
|
||||
assert(n == 150 && t == 0);
|
||||
}
|
||||
|
||||
void test_local_copy(void)
|
||||
{
|
||||
n = 0;
|
||||
k = 0;
|
||||
|
||||
{
|
||||
C1 c[10];
|
||||
C1 d(c[4]);
|
||||
}
|
||||
|
||||
assert(n == 10 && k == 1 && t == 0);
|
||||
}
|
||||
|
||||
void test_member_copy(void)
|
||||
{
|
||||
n = 0;
|
||||
k = 0;
|
||||
|
||||
{
|
||||
C2 d;
|
||||
C2 e(d);
|
||||
}
|
||||
|
||||
assert(n == 30 && k == 30 && t == 0);
|
||||
}
|
||||
|
||||
void test_local_assign(void)
|
||||
{
|
||||
n = 0;
|
||||
k = 0;
|
||||
m = 0;
|
||||
|
||||
{
|
||||
C1 c[10];
|
||||
C1 d[5];
|
||||
|
||||
d[4] = c[2];
|
||||
}
|
||||
|
||||
assert(n == 15 && k == 0 && m == 1 && t == 0);
|
||||
}
|
||||
|
||||
void test_member_assign(void)
|
||||
{
|
||||
n = 0;
|
||||
k = 0;
|
||||
m = 0;
|
||||
|
||||
{
|
||||
C2 d;
|
||||
C2 e;
|
||||
e = d;
|
||||
}
|
||||
|
||||
assert(n == 60 && k == 0 && m == 30 && t == 0);
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_local_init();
|
||||
test_member_init();
|
||||
|
||||
test_member_array_init();
|
||||
|
||||
test_local_copy();
|
||||
test_member_copy();
|
||||
|
||||
test_local_assign();
|
||||
test_member_assign();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
int a[10];
|
||||
|
||||
int get(int i)
|
||||
{
|
||||
return a[i];
|
||||
}
|
||||
|
||||
void put(int i, int x)
|
||||
{
|
||||
a[i] = x;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for(int j=0; j<10; j++)
|
||||
put(j, j);
|
||||
int s = -45;
|
||||
for(int j=0; j<10; j++)
|
||||
s += get(j);
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
int fg[15] = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int fl[15] = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610};
|
||||
|
||||
int sg = 0, sl = 0;
|
||||
|
||||
for(int i=0; i<15; i++)
|
||||
{
|
||||
sl += fl[i];
|
||||
sg += fg[i];
|
||||
}
|
||||
|
||||
assert(sl == 1596);
|
||||
assert(sg == 1596);
|
||||
|
||||
printf("%d %d\n", sl, sg);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
|
||||
int a(int * p, int x)
|
||||
{
|
||||
int y = x + 3;
|
||||
|
||||
p[y] = 1;
|
||||
p[y + 1] = 2;
|
||||
p[y + 2] = 3;
|
||||
p[y + 3] = 4;
|
||||
|
||||
return p[y] + p[y + 1] + p[y + 2] + p[y + 3];
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int t[16];
|
||||
|
||||
return a(t, 4) - 10;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int sum(int * a, int s)
|
||||
{
|
||||
int sum = 0;
|
||||
for(int i=0; i<s; i++)
|
||||
{
|
||||
sum += a[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
void copy(int * d, const int * s, int n)
|
||||
{
|
||||
for(int i=0; i<n ; i++)
|
||||
d[i] = s[i];
|
||||
}
|
||||
|
||||
void reverse(int * d, const int * s, int n)
|
||||
{
|
||||
for(int i=0; i<n ; i++)
|
||||
d[i] = s[n - i - 1];
|
||||
}
|
||||
|
||||
int sumb(int * a, char s)
|
||||
{
|
||||
int sum = 0;
|
||||
for(char i=0; i<s; i++)
|
||||
{
|
||||
sum += a[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
void copyb(int * d, const int * s, char n)
|
||||
{
|
||||
for(char i=0; i<n ; i++)
|
||||
d[i] = s[i];
|
||||
}
|
||||
|
||||
void reverseb(int * d, const int * s, char n)
|
||||
{
|
||||
for(char i=0; i<n ; i++)
|
||||
d[i] = s[n - i - 1];
|
||||
}
|
||||
|
||||
long suml(long * a, char s)
|
||||
{
|
||||
long sum = 0;
|
||||
for(char i=0; i<s; i++)
|
||||
{
|
||||
sum += a[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
void copyl(long * d, const long * s, char n)
|
||||
{
|
||||
for(char i=0; i<n ; i++)
|
||||
d[i] = s[i];
|
||||
}
|
||||
|
||||
void reversel(long * d, const long * s, char n)
|
||||
{
|
||||
for(char i=0; i<n ; i++)
|
||||
d[i] = s[n - i - 1];
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int a[100], b[100], c[100];
|
||||
long al[100], bl[100], cl[100];
|
||||
|
||||
for(int i=0; i<100; i++)
|
||||
{
|
||||
a[i] = i % 10;
|
||||
al[i] = i % 10;
|
||||
}
|
||||
|
||||
assert(sum(a, 100) == 450);
|
||||
|
||||
copy(b, a, 100);
|
||||
assert(sum(b, 100) == 450);
|
||||
reverse(c, a, 100);
|
||||
assert(sum(c, 100) == 450);
|
||||
assert(sumb(a, 100) == 450);
|
||||
copyb(b, a, 100);
|
||||
assert(sumb(b, 100) == 450);
|
||||
|
||||
reverseb(c, a, 100);
|
||||
assert(sumb(c, 100) == 450);
|
||||
|
||||
assert(suml(al, 100) == 450);
|
||||
|
||||
copyl(bl, al, 100);
|
||||
assert(suml(bl, 100) == 450);
|
||||
|
||||
reversel(cl, al, 100);
|
||||
assert(suml(cl, 100) == 450);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
float sum(float * a, int s)
|
||||
{
|
||||
float sum = 0;
|
||||
for(int i=0; i<s; i++)
|
||||
{
|
||||
sum += a[i];
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
float a[100];
|
||||
for(int i=0; i<100; i++)
|
||||
{
|
||||
a[i] = i % 10;
|
||||
}
|
||||
|
||||
assert(sum(a, 100) == 450);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
int a(char p[100])
|
||||
{
|
||||
int s = 0;
|
||||
for(int i=0; i<100; i++)
|
||||
s += p[i];
|
||||
return s;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char c[100];
|
||||
for(int i=0; i<100; i++)
|
||||
c[i] = i;
|
||||
return a(c) - 4950;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
int asum(int a, int b)
|
||||
{
|
||||
return __asm
|
||||
{
|
||||
clc
|
||||
lda a
|
||||
adc b
|
||||
sta accu
|
||||
lda a + 1
|
||||
adc b + 1
|
||||
sta accu + 1
|
||||
};
|
||||
}
|
||||
|
||||
int bsum(int a, int b)
|
||||
{
|
||||
puts("Hello\n");
|
||||
|
||||
return __asm
|
||||
{
|
||||
clc
|
||||
lda a
|
||||
adc b
|
||||
sta accu
|
||||
lda a + 1
|
||||
adc b + 1
|
||||
sta accu + 1
|
||||
};
|
||||
}
|
||||
|
||||
int b, t[10];
|
||||
|
||||
int bsome(int x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
int qsum(int a, int (* c)(int))
|
||||
{
|
||||
char n = 0;
|
||||
b = 0;
|
||||
for(int i=0; i<a; i++)
|
||||
{
|
||||
int j = c((char)i);
|
||||
__asm
|
||||
{
|
||||
clc
|
||||
lda j
|
||||
adc b
|
||||
sta b
|
||||
lda j + 1
|
||||
adc b + 1
|
||||
sta b + 1
|
||||
}
|
||||
t[n] += i;
|
||||
n = (n + 1) & 7;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
#define ASMTEST_ZP (0x00 | 0xf0)
|
||||
#define ASMTEST_TARGET (0x1000 * 0x0c)
|
||||
|
||||
int opPrecedenceAndParenthesis() {
|
||||
return __asm volatile {
|
||||
lda #(1 + 2 * (1 + 2)) // = #7
|
||||
sta [ASMTEST_TARGET + 1] // = $c001
|
||||
|
||||
lda #<ASMTEST_TARGET // = #$c0
|
||||
sta [ASMTEST_ZP] + 2 // = $f2
|
||||
|
||||
lda #>ASMTEST_TARGET + 1 // = #$01
|
||||
sta [ASMTEST_ZP + 1] // = $f1
|
||||
ldx #1
|
||||
lda (ASMTEST_ZP, x) // = (0xf0, 1)
|
||||
pha
|
||||
|
||||
lda #<ASMTEST_TARGET // = #$00
|
||||
sta [ASMTEST_ZP + 1] // = $f1
|
||||
ldy #1
|
||||
pla
|
||||
sta ASMTEST_ZP, y // = ($f1), 1
|
||||
|
||||
lda [([ASMTEST_TARGET])] + 1 // = $c001
|
||||
sta accu
|
||||
lda #(1 & 2) // = 0
|
||||
sta accu + 1
|
||||
};
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int x = asum(7007, 8008);
|
||||
int y = bsum(4004, 9009);
|
||||
|
||||
assert(x == 7007 + 8008 && y == 4004 + 9009);
|
||||
assert(qsum(10, bsome) == 45);
|
||||
assert(qsum(200, bsome) == 19900);
|
||||
|
||||
assert(opPrecedenceAndParenthesis() == 7);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
struct X
|
||||
{
|
||||
char t;
|
||||
long l;
|
||||
};
|
||||
|
||||
__striped X xs[16];
|
||||
X xf[16];
|
||||
char xp;
|
||||
|
||||
__noinline long tt(long n)
|
||||
{
|
||||
return n;
|
||||
}
|
||||
|
||||
inline auto & tas(void)
|
||||
{
|
||||
return xs[xp].l;
|
||||
}
|
||||
|
||||
inline auto & taf(void)
|
||||
{
|
||||
return xf[xp].l;
|
||||
}
|
||||
|
||||
long ts(char n)
|
||||
{
|
||||
return tt(tas());
|
||||
}
|
||||
|
||||
long tf(char n)
|
||||
{
|
||||
return tt(taf());
|
||||
}
|
||||
|
||||
inline auto bas(void)
|
||||
{
|
||||
return xs[xp].l;
|
||||
}
|
||||
|
||||
inline auto baf(void)
|
||||
{
|
||||
return xs[xp].l;
|
||||
}
|
||||
|
||||
long bs(char n)
|
||||
{
|
||||
return tt(bas());
|
||||
}
|
||||
|
||||
long bf(char n)
|
||||
{
|
||||
return tt(baf());
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for(char i=0; i<16; i++)
|
||||
{
|
||||
xs[i].l = i * i;
|
||||
xf[i].l = i * i;
|
||||
}
|
||||
|
||||
for(char i=0; i<16; i++)
|
||||
{
|
||||
xp = i;
|
||||
assert(ts(0) == i * i);
|
||||
assert(tf(0) == i * i);
|
||||
assert(bs(0) == i * i);
|
||||
assert(bf(0) == i * i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,476 @@
|
||||
rem @echo off
|
||||
|
||||
@call :test ambiguousoverload.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test array2dtest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test strparsetest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test shiftbyteaddconst.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test loopunrolltest.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test rolrortest.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test maskcheck.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test bitfields.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testn autorefreturn.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh opp_string.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh opp_hashmap.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh opp_array.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh opp_vector.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh opp_static_vector.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh opp_vector_string.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh opp_string_init.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh opp_optional.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh opp_numeric.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh opp_span.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh opp_streamtest.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh opp_pairtest.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh opp_parts.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh opp_list.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testn opp_functional.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh operatoroverload.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh virtualdestruct.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh vcalltest.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh vcalltree.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh constructortest.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testn copyconstructor.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh copyassign.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh arrayconstruct.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testh stdlibtest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test mathtest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test testint16.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test testint32.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test testint16mul.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test testsigned16mul.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test testsigned16div.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test recursiontest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test copyinitmove.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test fastcalltest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test strlen.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test strcmptest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test strcmptest2.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test memmovetest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test arraytest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test arraytestfloat.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test optiontest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test floatcmptest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test floatmultest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test floatinttest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test staticconsttest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test arrayinittest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test arrayindexintrangecheck.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test array2stringinittest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test testint16cmp.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test testint8cmp.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test testint32cmp.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test mixsigncmptest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test testinterval.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test cmprangeshortcuttest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test floatstringtest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test sprintftest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test qsorttest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testn plasma.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test loopdomtest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test loopboundtest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test byteindextest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test asmtest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testb bitshifttest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test arrparam.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test bsstest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test copyintvec.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test divmodtest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test divmod32test.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test fixmathtest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testn andmultest.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test enumswitch.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test incvector.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test structoffsettest2.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test structsplittest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test funcvartest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test variadic_macros.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test funcarraycall.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test structassigntest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test structmembertest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test structarraycopy.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test randsumtest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test longcodetest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test scrolltest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test charwintest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test linetest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test ptrinittest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test ptrarraycmptest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test cplxstructtest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testn stripedarraytest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testn stripedstructtest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testn mmultest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test tileexpand.cpp
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :testi volatiletest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test constlocaltest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@call :test structconditionaltest.c
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@exit /b 0
|
||||
|
||||
:error
|
||||
echo Failed with error #%errorlevel%.
|
||||
exit /b %errorlevel%
|
||||
|
||||
:testh
|
||||
..\bin\oscar64 -ea -g -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O2 -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O2 -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O2 -n -dHEAPCHECK %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O2 -xz -Oz -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O2 -Oo -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O2 -Ox -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O0 -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O0 -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -Os -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -Os -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O3 -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O3 -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O3 -n -dHEAPCHECK %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@exit /b 0
|
||||
|
||||
:test
|
||||
..\bin\oscar64 -ea -g -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O2 -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O2 -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O0 -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O0 -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -Os -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -Os -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O3 -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O3 -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O2 -xz -Oz -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O2 -Oo -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O2 -Ox -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@exit /b 0
|
||||
|
||||
:testb
|
||||
..\bin\oscar64 -ea -g -bc %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -bc -O2 %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -bc -O0 %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -bc -Os %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -bc -O3 %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@exit /b 0
|
||||
|
||||
:testn
|
||||
..\bin\oscar64 -ea -g -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O2 -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O0 -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -Os -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O3 -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O2 -xz -Oz -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O2 -Oo -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -ea -g -O2 -Ox -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
:testi
|
||||
..\bin\oscar64 -eai -g -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -eai -g -O2 -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -eai -g -O0 -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -eai -g -Os -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -eai -g -O3 -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -eai -g -O2 -xz -Oz -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -eai -g -O2 -Oo -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\bin\oscar64 -eai -g -O2 -Ox -n %~1
|
||||
@if %errorlevel% neq 0 goto :error
|
||||
|
||||
@exit /b 0
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef AUTOTEST_H
|
||||
#define AUTOTEST_H
|
||||
|
||||
struct TestIO
|
||||
{
|
||||
volatile char cnt0, cnt1;
|
||||
volatile unsigned dmaddr;
|
||||
volatile char dmdata;
|
||||
volatile char mirror0, mirror1, mirror2;
|
||||
volatile long cycles;
|
||||
volatile char scratch[4];
|
||||
};
|
||||
|
||||
#define testio (*((struct TestIO *)0xdd80))
|
||||
#define testio2 (*((struct TestIO *)0xdd90))
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,354 @@
|
||||
#include <assert.h>
|
||||
|
||||
struct A
|
||||
{
|
||||
char x : 4;
|
||||
char y : 1;
|
||||
char z : 3;
|
||||
};
|
||||
|
||||
A a = {7, 1, 2};
|
||||
|
||||
void test_char_fit(void)
|
||||
{
|
||||
assert(a.x == 7);
|
||||
assert(a.y == 1);
|
||||
assert(a.z == 2);
|
||||
assert(sizeof(A) == 1);
|
||||
|
||||
for(int i=0; i<16; i++)
|
||||
{
|
||||
a.x = i;
|
||||
a.y = 0;
|
||||
a.z = 3;
|
||||
assert(a.x == i);
|
||||
assert(a.y == 0);
|
||||
assert(a.z == 3);
|
||||
}
|
||||
}
|
||||
|
||||
struct B
|
||||
{
|
||||
char x : 6;
|
||||
char y : 6;
|
||||
char z : 6;
|
||||
char w : 6;
|
||||
};
|
||||
|
||||
B b = {11, 22, 33, 44};
|
||||
|
||||
void test_char_cross(void)
|
||||
{
|
||||
assert(b.x == 11);
|
||||
assert(b.y == 22);
|
||||
assert(b.z == 33);
|
||||
assert(b.w == 44);
|
||||
assert(sizeof(B) == 3);
|
||||
|
||||
for(int i=0; i<64; i++)
|
||||
{
|
||||
b.x = i * 1;
|
||||
b.y = i * 3;
|
||||
b.z = i * 5;
|
||||
b.w = i * 7;
|
||||
assert(b.x == ((i * 1) & 0x3f));
|
||||
assert(b.y == ((i * 3) & 0x3f));
|
||||
assert(b.z == ((i * 5) & 0x3f));
|
||||
assert(b.w == ((i * 7) & 0x3f));
|
||||
}
|
||||
}
|
||||
|
||||
struct C
|
||||
{
|
||||
unsigned x : 4;
|
||||
unsigned y : 1;
|
||||
unsigned z : 3;
|
||||
};
|
||||
|
||||
C c = {7, 1, 2};
|
||||
|
||||
void test_word_fit(void)
|
||||
{
|
||||
assert(c.x == 7);
|
||||
assert(c.y == 1);
|
||||
assert(c.z == 2);
|
||||
assert(sizeof(C) == 1);
|
||||
|
||||
for(int i=0; i<16; i++)
|
||||
{
|
||||
c.x = i;
|
||||
c.y = 0;
|
||||
c.z = 3;
|
||||
assert(c.x == i);
|
||||
assert(c.y == 0);
|
||||
assert(c.z == 3);
|
||||
}
|
||||
}
|
||||
|
||||
struct D
|
||||
{
|
||||
unsigned x : 10;
|
||||
unsigned y : 10;
|
||||
unsigned z : 10;
|
||||
unsigned w : 10;
|
||||
};
|
||||
|
||||
D d = {111, 222, 333, 444};
|
||||
|
||||
void test_word_cross(void)
|
||||
{
|
||||
assert(d.x == 111);
|
||||
assert(d.y == 222);
|
||||
assert(d.z == 333);
|
||||
assert(d.w == 444);
|
||||
assert(sizeof(D) == 5);
|
||||
|
||||
for(int i=0; i<1024; i++)
|
||||
{
|
||||
d.x = i * 1;
|
||||
d.y = i * 3;
|
||||
d.z = i * 5;
|
||||
d.w = i * 7;
|
||||
assert(d.x == ((i * 1) & 0x3ff));
|
||||
assert(d.y == ((i * 3) & 0x3ff));
|
||||
assert(d.z == ((i * 5) & 0x3ff));
|
||||
assert(d.w == ((i * 7) & 0x3ff));
|
||||
}
|
||||
}
|
||||
|
||||
struct E
|
||||
{
|
||||
unsigned long x : 4;
|
||||
unsigned long y : 1;
|
||||
unsigned long z : 3;
|
||||
};
|
||||
|
||||
E e = {7, 1, 2};
|
||||
|
||||
void test_dword_fit(void)
|
||||
{
|
||||
assert(e.x == 7);
|
||||
assert(e.y == 1);
|
||||
assert(e.z == 2);
|
||||
assert(sizeof(E) == 1);
|
||||
|
||||
for(int i=0; i<16; i++)
|
||||
{
|
||||
e.x = i;
|
||||
e.y = 0;
|
||||
e.z = 3;
|
||||
assert(e.x == i);
|
||||
assert(e.y == 0);
|
||||
assert(e.z == 3);
|
||||
}
|
||||
}
|
||||
|
||||
struct F
|
||||
{
|
||||
unsigned long x : 20;
|
||||
unsigned long y : 20;
|
||||
unsigned long z : 20;
|
||||
unsigned long w : 20;
|
||||
};
|
||||
|
||||
F f = {111111UL, 222222UL, 333333UL, 444444UL};
|
||||
|
||||
void test_dword_cross(void)
|
||||
{
|
||||
assert(f.x == 111111UL);
|
||||
assert(f.y == 222222UL);
|
||||
assert(f.z == 333333UL);
|
||||
assert(f.w == 444444UL);
|
||||
assert(sizeof(F) == 10);
|
||||
|
||||
for(int i=0; i<1024; i++)
|
||||
{
|
||||
f.x = i * 11UL;
|
||||
f.y = i * 33UL;
|
||||
f.z = i * 55UL;
|
||||
f.w = i * 77UL;
|
||||
assert(f.x == ((i * 11UL) & 0xfffffUL));
|
||||
assert(f.y == ((i * 33UL) & 0xfffffUL));
|
||||
assert(f.z == ((i * 55UL) & 0xfffffUL));
|
||||
assert(f.w == ((i * 77UL) & 0xfffffUL));
|
||||
}
|
||||
}
|
||||
|
||||
struct G
|
||||
{
|
||||
signed char x : 1;
|
||||
signed char y : 5;
|
||||
signed char z : 2;
|
||||
};
|
||||
|
||||
G g = {0, -1, -2};
|
||||
|
||||
void test_char_signed(void)
|
||||
{
|
||||
assert(g.x == 0);
|
||||
assert(g.y == -1);
|
||||
assert(g.z == -2);
|
||||
assert(sizeof(G) == 1);
|
||||
|
||||
for(int i=-16; i<16; i++)
|
||||
{
|
||||
g.x = -1;
|
||||
g.y = i;
|
||||
g.z = 1;
|
||||
assert(g.x == -1);
|
||||
assert(g.y == i);
|
||||
assert(g.z == 1);
|
||||
}
|
||||
}
|
||||
|
||||
struct H
|
||||
{
|
||||
int x : 10;
|
||||
int y : 10;
|
||||
int z : 10;
|
||||
int w : 10;
|
||||
};
|
||||
|
||||
H h = {111, -222, -333, 444};
|
||||
|
||||
void test_word_signed(void)
|
||||
{
|
||||
assert(h.x == 111);
|
||||
assert(h.y == -222);
|
||||
assert(h.z == -333);
|
||||
assert(h.w == 444);
|
||||
assert(sizeof(H) == 5);
|
||||
|
||||
for(int i=-32; i<32; i++)
|
||||
{
|
||||
h.x = i * 1;
|
||||
h.y = i * 3;
|
||||
h.z = i * 5;
|
||||
h.w = i * 7;
|
||||
assert(h.x == i * 1);
|
||||
assert(h.y == i * 3);
|
||||
assert(h.z == i * 5);
|
||||
assert(h.w == i * 7);
|
||||
}
|
||||
}
|
||||
|
||||
void test_inc_char_fit(void)
|
||||
{
|
||||
A ai;
|
||||
ai.x = 7;
|
||||
ai.y = 1;
|
||||
ai.z = 2;
|
||||
|
||||
for(int i=0; i<16; i++)
|
||||
{
|
||||
assert(ai.x == ((7 + i) & 15));
|
||||
assert(ai.y == ((1 + i) & 1));
|
||||
assert(ai.z == ((2 + i) & 7));
|
||||
ai.x++;
|
||||
ai.y++;
|
||||
ai.z++;
|
||||
}
|
||||
}
|
||||
|
||||
void test_inc_char_cross(void)
|
||||
{
|
||||
B bi;
|
||||
bi.x = 11;
|
||||
bi.y = 22;
|
||||
bi.z = 33;
|
||||
bi.w = 44;
|
||||
|
||||
for(int i=0; i<64; i++)
|
||||
{
|
||||
assert(bi.x == ((11 + i) & 0x3f));
|
||||
assert(bi.y == ((22 + i) & 0x3f));
|
||||
assert(bi.z == ((33 + i) & 0x3f));
|
||||
assert(bi.w == ((44 + i) & 0x3f));
|
||||
bi.x++;
|
||||
bi.y++;
|
||||
bi.z++;
|
||||
bi.w++;
|
||||
}
|
||||
}
|
||||
|
||||
void test_add_char_cross(void)
|
||||
{
|
||||
B bi= {0};
|
||||
bi.x = 11;
|
||||
bi.y = 22;
|
||||
bi.z = 33;
|
||||
bi.w = 44;
|
||||
|
||||
for(int i=0; i<64; i++)
|
||||
{
|
||||
assert(bi.x == ((11 + 5 * i) & 0x3f));
|
||||
assert(bi.y == ((22 + 21 * i) & 0x3f));
|
||||
assert(bi.z == ((33 - 4 * i) & 0x3f));
|
||||
assert(bi.w == ((44 - 11 * i) & 0x3f));
|
||||
bi.x += 5;
|
||||
bi.y += 21;
|
||||
bi.z -= 4;
|
||||
bi.w -= 11;
|
||||
}
|
||||
}
|
||||
|
||||
void test_add_word_fit(void)
|
||||
{
|
||||
C ci = {0};
|
||||
|
||||
ci.x = 7;
|
||||
ci.y = 1;
|
||||
ci.z = 2;
|
||||
|
||||
for(int i=0; i<16; i++)
|
||||
{
|
||||
assert(ci.x == ((7 + 5 * i) & 15));
|
||||
assert(ci.y == ((1 + 21 * i) & 1));
|
||||
assert(ci.z == ((2 - 4 * i) & 7));
|
||||
ci.x += 5;
|
||||
ci.y += 21;
|
||||
ci.z -= 4;
|
||||
}
|
||||
}
|
||||
|
||||
void test_add_word_cross(void)
|
||||
{
|
||||
D di = {0};
|
||||
|
||||
di.x = 111;
|
||||
di.y = 222;
|
||||
di.z = 333;
|
||||
di.w = 444;
|
||||
|
||||
for(int i=0; i<1024; i++)
|
||||
{
|
||||
assert(di.x == ((111 + 5 * i) & 0x3ff));
|
||||
assert(di.y == ((222 + 21 * i) & 0x3ff));
|
||||
assert(di.z == ((333 - 4 * i) & 0x3ff));
|
||||
assert(di.w == ((444 - 11 * i) & 0x3ff));
|
||||
di.x += 5;
|
||||
di.y += 21;
|
||||
di.z -= 4;
|
||||
di.w -= 11;
|
||||
}
|
||||
}
|
||||
int main(void)
|
||||
{
|
||||
test_char_fit();
|
||||
test_char_cross();
|
||||
test_word_fit();
|
||||
test_word_cross();
|
||||
test_dword_fit();
|
||||
test_dword_cross();
|
||||
test_char_signed();
|
||||
test_word_signed();
|
||||
|
||||
test_inc_char_fit();
|
||||
test_inc_char_cross();
|
||||
test_add_char_cross();
|
||||
|
||||
test_add_word_fit();
|
||||
test_add_word_cross();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,414 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#pragma region( main, 0x0a00, 0xd000, , , {code, data, bss, heap, stack} )
|
||||
|
||||
unsigned shl1b(int n)
|
||||
{
|
||||
return 1 << n;
|
||||
}
|
||||
|
||||
unsigned shl1n(int n)
|
||||
{
|
||||
return 1 << n;
|
||||
}
|
||||
|
||||
#pragma native(shl1n)
|
||||
|
||||
unsigned shr1b(int n)
|
||||
{
|
||||
return 0x8000 >> n;
|
||||
}
|
||||
|
||||
unsigned shr1n(int n)
|
||||
{
|
||||
return 0x8000 >> n;
|
||||
}
|
||||
|
||||
#pragma native(shr1n)
|
||||
|
||||
unsigned shl4b(int n)
|
||||
{
|
||||
return 0x0010 << n;
|
||||
}
|
||||
|
||||
unsigned shl4n(int n)
|
||||
{
|
||||
return 0x0010 << n;
|
||||
}
|
||||
|
||||
#pragma native(shl4n)
|
||||
|
||||
unsigned shr4b(int n)
|
||||
{
|
||||
return 0x0800 >> n;
|
||||
}
|
||||
|
||||
unsigned shr4n(int n)
|
||||
{
|
||||
return 0x0800 >> n;
|
||||
}
|
||||
|
||||
#pragma native(shr4n)
|
||||
|
||||
|
||||
unsigned shl8b(int n)
|
||||
{
|
||||
return 0x0100 << n;
|
||||
}
|
||||
|
||||
unsigned shl8n(int n)
|
||||
{
|
||||
return 0x0100 << n;
|
||||
}
|
||||
|
||||
#pragma native(shl8n)
|
||||
|
||||
unsigned shr8b(int n)
|
||||
{
|
||||
return 0x0080 >> n;
|
||||
}
|
||||
|
||||
unsigned shr8n(int n)
|
||||
{
|
||||
return 0x0080 >> n;
|
||||
}
|
||||
|
||||
#pragma native(shr8n)
|
||||
|
||||
|
||||
void shl8xb(unsigned char xu, signed char xi)
|
||||
{
|
||||
unsigned char ua[16];
|
||||
signed char ia[16];
|
||||
#assign s 0
|
||||
#repeat
|
||||
ua[s] = xu << s;
|
||||
ia[s] = xi << s;
|
||||
#assign s s + 1
|
||||
#until s == 16
|
||||
|
||||
for(int i=0; i<16; i++)
|
||||
{
|
||||
assert(ua[i] == (unsigned char)(xu << i));
|
||||
assert(ia[i] == (signed char)(xi << i));
|
||||
}
|
||||
}
|
||||
|
||||
void shr8xb(unsigned char xu, signed char xi)
|
||||
{
|
||||
unsigned char ua[16];
|
||||
signed char ia[16];
|
||||
#assign s 0
|
||||
#repeat
|
||||
ua[s] = xu >> s;
|
||||
ia[s] = xi >> s;
|
||||
#assign s s + 1
|
||||
#until s == 16
|
||||
|
||||
for(int i=0; i<16; i++)
|
||||
{
|
||||
assert(ua[i] == (unsigned char)(xu >> i));
|
||||
assert(ia[i] == (signed char)(xi >> i));
|
||||
}
|
||||
}
|
||||
|
||||
void shl8xn(unsigned char xu, signed char xi)
|
||||
{
|
||||
unsigned char ua[16];
|
||||
signed char ia[16];
|
||||
#assign s 0
|
||||
#repeat
|
||||
ua[s] = xu << s;
|
||||
ia[s] = xi << s;
|
||||
#assign s s + 1
|
||||
#until s == 16
|
||||
|
||||
for(int i=0; i<16; i++)
|
||||
{
|
||||
assert(ua[i] == (unsigned char)(xu << i));
|
||||
assert(ia[i] == (signed char)(xi << i));
|
||||
}
|
||||
}
|
||||
|
||||
void shr8xn(unsigned char xu, signed char xi)
|
||||
{
|
||||
unsigned char ua[16];
|
||||
signed char ia[16];
|
||||
#assign s 0
|
||||
#repeat
|
||||
ua[s] = xu >> s;
|
||||
ia[s] = xi >> s;
|
||||
#assign s s + 1
|
||||
#until s == 16
|
||||
|
||||
for(int i=0; i<16; i++)
|
||||
{
|
||||
assert(ua[i] == (unsigned char)(xu >> i));
|
||||
assert(ia[i] == (signed char)(xi >> i));
|
||||
}
|
||||
}
|
||||
|
||||
#pragma native(shl8xn)
|
||||
#pragma native(shr8xn)
|
||||
|
||||
|
||||
|
||||
|
||||
void shl16b(unsigned xu, int xi)
|
||||
{
|
||||
unsigned ua[16];
|
||||
int ia[16];
|
||||
#assign s 0
|
||||
#repeat
|
||||
ua[s] = xu << s;
|
||||
ia[s] = xi << s;
|
||||
#assign s s + 1
|
||||
#until s == 16
|
||||
|
||||
for(int i=0; i<16; i++)
|
||||
{
|
||||
assert(ua[i] == xu << i);
|
||||
assert(ia[i] == xi << i);
|
||||
}
|
||||
}
|
||||
|
||||
void shr16b(unsigned xu, int xi)
|
||||
{
|
||||
unsigned ua[16];
|
||||
int ia[16];
|
||||
#assign s 0
|
||||
#repeat
|
||||
ua[s] = xu >> s;
|
||||
ia[s] = xi >> s;
|
||||
#assign s s + 1
|
||||
#until s == 16
|
||||
|
||||
for(int i=0; i<16; i++)
|
||||
{
|
||||
assert(ua[i] == xu >> i);
|
||||
assert(ia[i] == xi >> i);
|
||||
}
|
||||
}
|
||||
|
||||
void shl16n(unsigned xu, int xi)
|
||||
{
|
||||
unsigned ua[16];
|
||||
int ia[16];
|
||||
#assign s 0
|
||||
#repeat
|
||||
ua[s] = xu << s;
|
||||
ia[s] = xi << s;
|
||||
#assign s s + 1
|
||||
#until s == 16
|
||||
|
||||
for(int i=0; i<16; i++)
|
||||
{
|
||||
assert(ua[i] == xu << i);
|
||||
assert(ia[i] == xi << i);
|
||||
}
|
||||
}
|
||||
|
||||
void shr16n(unsigned xu, int xi)
|
||||
{
|
||||
unsigned ua[16];
|
||||
int ia[16];
|
||||
#assign s 0
|
||||
#repeat
|
||||
ua[s] = xu >> s;
|
||||
ia[s] = xi >> s;
|
||||
#assign s s + 1
|
||||
#until s == 16
|
||||
|
||||
for(int i=0; i<16; i++)
|
||||
{
|
||||
assert(ua[i] == xu >> i);
|
||||
assert(ia[i] == xi >> i);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma native(shl16n)
|
||||
#pragma native(shr16n)
|
||||
|
||||
|
||||
void shl32b(unsigned long xu, long xi)
|
||||
{
|
||||
unsigned long ua[32];
|
||||
long ia[32];
|
||||
#assign s 0
|
||||
#repeat
|
||||
ua[s] = xu << s;
|
||||
ia[s] = xi << s;
|
||||
#assign s s + 1
|
||||
#until s == 32
|
||||
|
||||
for(int i=0; i<32; i++)
|
||||
{
|
||||
assert(ua[i] == xu << i);
|
||||
assert(ia[i] == xi << i);
|
||||
}
|
||||
}
|
||||
|
||||
void shr32b(unsigned long xu, long xi)
|
||||
{
|
||||
unsigned long ua[32];
|
||||
long ia[32];
|
||||
#assign s 0
|
||||
#repeat
|
||||
ua[s] = xu >> s;
|
||||
ia[s] = xi >> s;
|
||||
#assign s s + 1
|
||||
#until s == 32
|
||||
|
||||
for(int i=0; i<32; i++)
|
||||
{
|
||||
assert(ua[i] == xu >> i);
|
||||
assert(ia[i] == xi >> i);
|
||||
}
|
||||
}
|
||||
|
||||
void shl32n(unsigned long xu, long xi)
|
||||
{
|
||||
unsigned long ua[32];
|
||||
long ia[32];
|
||||
#assign s 0
|
||||
#repeat
|
||||
ua[s] = xu << s;
|
||||
ia[s] = xi << s;
|
||||
#assign s s + 1
|
||||
#until s == 32
|
||||
|
||||
for(int i=0; i<32; i++)
|
||||
{
|
||||
assert(ua[i] == xu << i);
|
||||
assert(ia[i] == xi << i);
|
||||
}
|
||||
}
|
||||
|
||||
void shr32n(unsigned long xu, long xi)
|
||||
{
|
||||
unsigned long ua[32];
|
||||
long ia[32];
|
||||
#assign s 0
|
||||
#repeat
|
||||
ua[s] = xu >> s;
|
||||
ia[s] = xi >> s;
|
||||
#assign s s + 1
|
||||
#until s == 32
|
||||
|
||||
for(int i=0; i<32; i++)
|
||||
{
|
||||
assert(ua[i] == xu >> i);
|
||||
assert(ia[i] == xi >> i);
|
||||
}
|
||||
}
|
||||
|
||||
void shl1_32n(void)
|
||||
{
|
||||
static const unsigned long m[] = {
|
||||
#for(i, 32) 1ul << i,
|
||||
};
|
||||
|
||||
for(int i=0; i<32; i++)
|
||||
{
|
||||
assert(1ul << i == m[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma native(shl32n)
|
||||
#pragma native(shr32n)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
*(volatile char *)0x01 = 0x36;
|
||||
|
||||
for(int i=0; i<32; i++)
|
||||
{
|
||||
printf("1: %.4x : %.4x | %.4x : %.4x\n", shl1b(i), shl1n(i), shr1b(i), shr1n(i));
|
||||
assert(shl1b(i) == shl1n(i));
|
||||
assert(shr1b(i) == shr1n(i));
|
||||
}
|
||||
|
||||
for(int i=0; i<32; i++)
|
||||
{
|
||||
printf("4: %.4x : %.4x | %.4x : %.4x\n", shl4b(i), shl4n(i), shr4b(i), shr4n(i));
|
||||
assert(shl4b(i) == shl4n(i));
|
||||
assert(shr4b(i) == shr4n(i));
|
||||
}
|
||||
|
||||
for(int i=0; i<32; i++)
|
||||
{
|
||||
printf("8: %.4x : %.4x | %.4x : %.4x\n", shl8b(i), shl8n(i), shr8b(i), shr8n(i));
|
||||
assert(shl8b(i) == shl8n(i));
|
||||
assert(shr8b(i) == shr8n(i));
|
||||
}
|
||||
|
||||
shl8xb(0x00, 0x00);
|
||||
shl8xb(0xff, 0xff);
|
||||
shl8xb(0x34, 0x34);
|
||||
shl8xb(0xdc, 0xdc);
|
||||
|
||||
shr8xb(0x00, 0x00);
|
||||
shr8xb(0xff, 0xff);
|
||||
shr8xb(0x34, 0x34);
|
||||
shr8xb(0xdc, 0xdc);
|
||||
|
||||
shl8xn(0x00, 0x00);
|
||||
shl8xn(0xff, 0xff);
|
||||
shl8xn(0x34, 0x34);
|
||||
shl8xn(0xdc, 0xdc);
|
||||
|
||||
shr8xn(0x00, 0x00);
|
||||
shr8xn(0xff, 0xff);
|
||||
shr8xn(0x34, 0x34);
|
||||
shr8xn(0xdc, 0xdc);
|
||||
|
||||
shl16b(0x0000, 0x0000);
|
||||
shl16b(0xffff, 0xffff);
|
||||
shl16b(0x1234, 0x1234);
|
||||
shl16b(0xfedc, 0xfedc);
|
||||
|
||||
shr16b(0x0000, 0x0000);
|
||||
shr16b(0xffff, 0xffff);
|
||||
shr16b(0x1234, 0x1234);
|
||||
shr16b(0xfedc, 0xfedc);
|
||||
|
||||
shl16n(0x0000, 0x0000);
|
||||
|
||||
shl16n(0xffff, 0xffff);
|
||||
shl16n(0x1234, 0x1234);
|
||||
shl16n(0xfedc, 0xfedc);
|
||||
|
||||
shr16n(0x0000, 0x0000);
|
||||
shr16n(0xffff, 0xffff);
|
||||
shr16n(0x1234, 0x1234);
|
||||
shr16n(0xfedc, 0xfedc);
|
||||
|
||||
shl32b(0x00000000UL, 0x00000000L);
|
||||
shl32b(0x00000001UL, 0x00000001L);
|
||||
shl32b(0xffffffffUL, 0xffffffffL);
|
||||
shl32b(0x12345678UL, 0x12345678L);
|
||||
shl32b(0xfedcba98UL, 0xfedcba98L);
|
||||
|
||||
shr32b(0x00000000UL, 0x00000000L);
|
||||
shr32b(0x00000001UL, 0x00000001L);
|
||||
shr32b(0xffffffffUL, 0xffffffffL);
|
||||
shr32b(0x12345678UL, 0x12345678L);
|
||||
shr32b(0xfedcba98UL, 0xfedcba98L);
|
||||
|
||||
shl32n(0x00000000UL, 0x00000000L);
|
||||
shl32n(0x00000001UL, 0x00000001L);
|
||||
shl32n(0xffffffffUL, 0xffffffffL);
|
||||
shl32n(0x12345678UL, 0x12345678L);
|
||||
shl32n(0xfedcba98UL, 0xfedcba98L);
|
||||
|
||||
shr32n(0x00000000UL, 0x00000000L);
|
||||
shr32n(0x00000001UL, 0x00000001L);
|
||||
shr32n(0xffffffffUL, 0xffffffffL);
|
||||
shr32n(0x12345678UL, 0x12345678L);
|
||||
shr32n(0xfedcba98UL, 0xfedcba98L);
|
||||
|
||||
shl1_32n();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char ch[100];
|
||||
char p[] = "HELLO";
|
||||
int v[10];
|
||||
int w[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
|
||||
int sum(int * k)
|
||||
{
|
||||
int s = 0;
|
||||
for(int i=0; i<10; i++)
|
||||
s += k[i];
|
||||
return s;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
strcpy(ch, p);
|
||||
strcat(ch, " WORLD");
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
v[i] = w[i];
|
||||
|
||||
return strcmp(ch, "HELLO WORLD") + sum(v) - 55;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
char a[20];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for(char i=0; i<20; i++)
|
||||
a[i] = i;
|
||||
char x = 0;
|
||||
for(char i=0; i<20; i++)
|
||||
x += a[i];
|
||||
|
||||
assert(x == 190);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#include <c64/charwin.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
CharWin cw;
|
||||
|
||||
cwin_init(&cw, (char *)0x0400, 2, 2, 32, 20);
|
||||
|
||||
cwin_clear(&cw);
|
||||
|
||||
for(int y=0; y<20; y++)
|
||||
{
|
||||
for(int x=0; x<32; x++)
|
||||
{
|
||||
assert(cwin_getat_char_raw(&cw, x, y) == ' ');
|
||||
}
|
||||
}
|
||||
|
||||
for(int y=0; y<20; y++)
|
||||
{
|
||||
for(int x=0; x<32; x++)
|
||||
{
|
||||
cwin_putat_char(&cw, x, y, p'a' - 1 + x, 7);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int y=0; y<20; y++)
|
||||
{
|
||||
for(int x=0; x<32; x++)
|
||||
{
|
||||
assert(cwin_getat_char(&cw, x, y) == p'a' -1 + x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int y=0; y<20; y++)
|
||||
{
|
||||
for(int x=0; x<32; x++)
|
||||
{
|
||||
cwin_putat_char(&cw, x, y, p'A' - 1 + x, 8);
|
||||
}
|
||||
}
|
||||
|
||||
for(int y=0; y<20; y++)
|
||||
{
|
||||
for(int x=0; x<32; x++)
|
||||
{
|
||||
cwin_putat_char_raw(&cw, x, y, x + 32 * y, 8);
|
||||
}
|
||||
}
|
||||
|
||||
for(int y=0; y<8; y++)
|
||||
{
|
||||
for(int x=0; x<32; x++)
|
||||
{
|
||||
assert(cwin_getat_char_raw(&cw, x, y) == x + 32 * y);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
#include <assert.h>
|
||||
|
||||
void check_s_lt(void)
|
||||
{
|
||||
int a5 = 0, a10 = 0, a15 = 0;
|
||||
|
||||
for(int i=5; i<15; i++)
|
||||
{
|
||||
if (i < 5)
|
||||
a5++;
|
||||
if (i < 10)
|
||||
a10++;
|
||||
if (i < 15)
|
||||
a15++;
|
||||
}
|
||||
|
||||
assert(a5 == 0);
|
||||
assert(a10 == 5);
|
||||
assert(a15 == 10);
|
||||
}
|
||||
|
||||
void check_s_le(void)
|
||||
{
|
||||
int a4 = 0, a5 = 0, a10 = 0, a14 = 0, a15 = 0;
|
||||
|
||||
for(int i=5; i<15; i++)
|
||||
{
|
||||
if (i <= 4)
|
||||
a4++;
|
||||
if (i <= 5)
|
||||
a5++;
|
||||
if (i <= 10)
|
||||
a10++;
|
||||
if (i <= 14)
|
||||
a14++;
|
||||
if (i <= 15)
|
||||
a15++;
|
||||
}
|
||||
|
||||
assert(a4 == 0);
|
||||
assert(a5 == 1);
|
||||
assert(a10 == 6);
|
||||
assert(a14 == 10);
|
||||
assert(a15 == 10);
|
||||
}
|
||||
|
||||
void check_s_ge(void)
|
||||
{
|
||||
int a5 = 0, a10 = 0, a15 = 0;
|
||||
|
||||
for(int i=5; i<15; i++)
|
||||
{
|
||||
if (i >= 5)
|
||||
a5++;
|
||||
if (i >= 10)
|
||||
a10++;
|
||||
if (i >= 15)
|
||||
a15++;
|
||||
}
|
||||
|
||||
assert(a5 == 10);
|
||||
assert(a10 == 5);
|
||||
assert(a15 == 0);
|
||||
}
|
||||
|
||||
void check_s_gt(void)
|
||||
{
|
||||
int a4 = 0, a5 = 0, a10 = 0, a14 = 0, a15 = 0;
|
||||
|
||||
for(int i=5; i<15; i++)
|
||||
{
|
||||
if (i > 4)
|
||||
a4++;
|
||||
if (i > 5)
|
||||
a5++;
|
||||
if (i > 10)
|
||||
a10++;
|
||||
if (i > 14)
|
||||
a14++;
|
||||
if (i > 15)
|
||||
a15++;
|
||||
}
|
||||
|
||||
assert(a4 == 10);
|
||||
assert(a5 == 9);
|
||||
assert(a10 == 4);
|
||||
assert(a14 == 0);
|
||||
assert(a15 == 0);
|
||||
}
|
||||
|
||||
void check_s_eq(void)
|
||||
{
|
||||
int a4 = 0, a5 = 0, a10 = 0, a14 = 0, a15 = 0;
|
||||
|
||||
for(int i=5; i<15; i++)
|
||||
{
|
||||
if (i == 4)
|
||||
a4++;
|
||||
if (i == 5)
|
||||
a5++;
|
||||
if (i == 10)
|
||||
a10++;
|
||||
if (i == 14)
|
||||
a14++;
|
||||
if (i == 15)
|
||||
a15++;
|
||||
}
|
||||
|
||||
assert(a4 == 0);
|
||||
assert(a5 == 1);
|
||||
assert(a10 == 1);
|
||||
assert(a14 == 1);
|
||||
assert(a15 == 0);
|
||||
}
|
||||
|
||||
void check_s_ne(void)
|
||||
{
|
||||
int a4 = 0, a5 = 0, a10 = 0, a14 = 0, a15 = 0;
|
||||
|
||||
for(int i=5; i<15; i++)
|
||||
{
|
||||
if (i != 4)
|
||||
a4++;
|
||||
if (i != 5)
|
||||
a5++;
|
||||
if (i != 10)
|
||||
a10++;
|
||||
if (i != 14)
|
||||
a14++;
|
||||
if (i != 15)
|
||||
a15++;
|
||||
}
|
||||
|
||||
assert(a4 == 10);
|
||||
assert(a5 == 9);
|
||||
assert(a10 == 9);
|
||||
assert(a14 == 9);
|
||||
assert(a15 == 10);
|
||||
}
|
||||
|
||||
void check_u_lt(void)
|
||||
{
|
||||
int a5 = 0, a10 = 0, a15 = 0;
|
||||
|
||||
for(unsigned i=5; i<15; i++)
|
||||
{
|
||||
if (i < 5)
|
||||
a5++;
|
||||
if (i < 10)
|
||||
a10++;
|
||||
if (i < 15)
|
||||
a15++;
|
||||
}
|
||||
|
||||
assert(a5 == 0);
|
||||
assert(a10 == 5);
|
||||
assert(a15 == 10);
|
||||
}
|
||||
|
||||
void check_u_le(void)
|
||||
{
|
||||
int a4 = 0, a5 = 0, a10 = 0, a14 = 0, a15 = 0;
|
||||
|
||||
for(unsigned i=5; i<15; i++)
|
||||
{
|
||||
if (i <= 4)
|
||||
a4++;
|
||||
if (i <= 5)
|
||||
a5++;
|
||||
if (i <= 10)
|
||||
a10++;
|
||||
if (i <= 14)
|
||||
a14++;
|
||||
if (i <= 15)
|
||||
a15++;
|
||||
}
|
||||
|
||||
assert(a4 == 0);
|
||||
assert(a5 == 1);
|
||||
assert(a10 == 6);
|
||||
assert(a14 == 10);
|
||||
assert(a15 == 10);
|
||||
}
|
||||
|
||||
void check_u_ge(void)
|
||||
{
|
||||
int a5 = 0, a10 = 0, a15 = 0;
|
||||
|
||||
for(unsigned i=5; i<15; i++)
|
||||
{
|
||||
if (i >= 5)
|
||||
a5++;
|
||||
if (i >= 10)
|
||||
a10++;
|
||||
if (i >= 15)
|
||||
a15++;
|
||||
}
|
||||
|
||||
assert(a5 == 10);
|
||||
assert(a10 == 5);
|
||||
assert(a15 == 0);
|
||||
}
|
||||
|
||||
void check_u_gt(void)
|
||||
{
|
||||
int a4 = 0, a5 = 0, a10 = 0, a14 = 0, a15 = 0;
|
||||
|
||||
for(unsigned i=5; i<15; i++)
|
||||
{
|
||||
if (i > 4)
|
||||
a4++;
|
||||
if (i > 5)
|
||||
a5++;
|
||||
if (i > 10)
|
||||
a10++;
|
||||
if (i > 14)
|
||||
a14++;
|
||||
if (i > 15)
|
||||
a15++;
|
||||
}
|
||||
|
||||
assert(a4 == 10);
|
||||
assert(a5 == 9);
|
||||
assert(a10 == 4);
|
||||
assert(a14 == 0);
|
||||
assert(a15 == 0);
|
||||
}
|
||||
|
||||
void check_u_eq(void)
|
||||
{
|
||||
int a4 = 0, a5 = 0, a10 = 0, a14 = 0, a15 = 0;
|
||||
|
||||
for(unsigned i=5; i<15; i++)
|
||||
{
|
||||
if (i == 4)
|
||||
a4++;
|
||||
if (i == 5)
|
||||
a5++;
|
||||
if (i == 10)
|
||||
a10++;
|
||||
if (i == 14)
|
||||
a14++;
|
||||
if (i == 15)
|
||||
a15++;
|
||||
}
|
||||
|
||||
assert(a4 == 0);
|
||||
assert(a5 == 1);
|
||||
assert(a10 == 1);
|
||||
assert(a14 == 1);
|
||||
assert(a15 == 0);
|
||||
}
|
||||
|
||||
void check_u_ne(void)
|
||||
{
|
||||
int a4 = 0, a5 = 0, a10 = 0, a14 = 0, a15 = 0;
|
||||
|
||||
for(unsigned i=5; i<15; i++)
|
||||
{
|
||||
if (i != 4)
|
||||
a4++;
|
||||
if (i != 5)
|
||||
a5++;
|
||||
if (i != 10)
|
||||
a10++;
|
||||
if (i != 14)
|
||||
a14++;
|
||||
if (i != 15)
|
||||
a15++;
|
||||
}
|
||||
|
||||
assert(a4 == 10);
|
||||
assert(a5 == 9);
|
||||
assert(a10 == 9);
|
||||
assert(a14 == 9);
|
||||
assert(a15 == 10);
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
check_s_ne();
|
||||
check_s_eq();
|
||||
check_s_lt();
|
||||
check_s_le();
|
||||
check_s_gt();
|
||||
check_s_ge();
|
||||
|
||||
check_u_ne();
|
||||
check_u_eq();
|
||||
check_u_lt();
|
||||
check_u_le();
|
||||
check_u_gt();
|
||||
check_u_ge();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
static int counter;
|
||||
|
||||
static int read_const_local_twice(void)
|
||||
{
|
||||
const int value = ++counter;
|
||||
return value + value;
|
||||
}
|
||||
|
||||
static bool update(unsigned char* value)
|
||||
{
|
||||
const unsigned char before = *value;
|
||||
const unsigned char after = before + 2;
|
||||
const bool changed = after != before;
|
||||
|
||||
*value = after;
|
||||
return changed;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
assert(read_const_local_twice() == 2);
|
||||
assert(counter == 1);
|
||||
|
||||
unsigned char value = 7;
|
||||
assert(update(&value));
|
||||
assert(value == 9);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
#include <assert.h>
|
||||
|
||||
int t, n;
|
||||
|
||||
struct C1
|
||||
{
|
||||
int a;
|
||||
|
||||
C1(int x);
|
||||
~C1(void);
|
||||
};
|
||||
|
||||
C1::C1(int x) : a(x)
|
||||
{
|
||||
t += a;
|
||||
n++;
|
||||
}
|
||||
|
||||
C1::~C1(void)
|
||||
{
|
||||
t -= a;
|
||||
}
|
||||
|
||||
void test_base(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C1 x(2);
|
||||
C1 y(1);
|
||||
}
|
||||
|
||||
assert(t == 0 && n == 2);
|
||||
}
|
||||
|
||||
void test_base_loop(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
{
|
||||
C1 x(2);
|
||||
C1 y(1);
|
||||
}
|
||||
|
||||
assert(t == 0 && n == 20);
|
||||
}
|
||||
|
||||
struct C2
|
||||
{
|
||||
C1 c, d;
|
||||
|
||||
C2(void);
|
||||
};
|
||||
|
||||
C2::C2(void)
|
||||
: c(7), d(11)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void test_member(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C2 x();
|
||||
C2 y();
|
||||
}
|
||||
|
||||
assert(t == 0 && n == 4);
|
||||
}
|
||||
|
||||
void test_member_loop(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
{
|
||||
C2 x();
|
||||
C2 y();
|
||||
}
|
||||
|
||||
assert(t == 0 && n == 40);
|
||||
}
|
||||
|
||||
struct C3
|
||||
{
|
||||
C2 x, y;
|
||||
};
|
||||
|
||||
void test_default(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C3 x();
|
||||
C3 y();
|
||||
}
|
||||
|
||||
assert(t == 0 && n == 8);
|
||||
}
|
||||
|
||||
void test_default_loop(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
{
|
||||
C3 x();
|
||||
C3 y();
|
||||
}
|
||||
|
||||
assert(t == 0 && n == 80);
|
||||
}
|
||||
|
||||
inline void test_inline_x(void)
|
||||
{
|
||||
C1 x(1), y(2);
|
||||
}
|
||||
|
||||
void test_inline(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
test_inline_x();
|
||||
|
||||
assert(t == 0 && n == 2);
|
||||
}
|
||||
|
||||
inline void test_inline_xr(void)
|
||||
{
|
||||
C1 x(1), y(2);
|
||||
|
||||
{
|
||||
C1 x(3);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void test_inline_return(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
test_inline_xr();
|
||||
|
||||
assert(t == 0 && n == 3);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_base();
|
||||
test_base_loop();
|
||||
|
||||
test_member();
|
||||
test_member_loop();
|
||||
|
||||
test_default();
|
||||
test_default_loop();
|
||||
|
||||
test_inline();
|
||||
test_inline_return();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
#include <assert.h>
|
||||
|
||||
int t, n;
|
||||
|
||||
struct C0
|
||||
{
|
||||
int u;
|
||||
|
||||
C0(int a);
|
||||
~C0(void);
|
||||
};
|
||||
|
||||
C0::C0(int a) : u(a)
|
||||
{
|
||||
t += u;
|
||||
n++;
|
||||
}
|
||||
|
||||
C0::~C0(void)
|
||||
{
|
||||
t -= u;
|
||||
}
|
||||
|
||||
struct C1
|
||||
{
|
||||
int u;
|
||||
|
||||
C1(int a);
|
||||
~C1(void);
|
||||
C1(const C1 & c);
|
||||
C1 & operator=(const C1 & c);
|
||||
};
|
||||
|
||||
C1::C1(int a) : u(a)
|
||||
{
|
||||
t += u;
|
||||
n++;
|
||||
}
|
||||
|
||||
C1::~C1(void)
|
||||
{
|
||||
t -= u;
|
||||
}
|
||||
|
||||
C1::C1(const C1 & c) : u(c.u)
|
||||
{
|
||||
t += u;
|
||||
n++;
|
||||
}
|
||||
|
||||
C1 & C1::operator=(const C1 & c)
|
||||
{
|
||||
t -= u;
|
||||
u = c.u;
|
||||
t += u;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void test_assign(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C1 c(4);
|
||||
C1 d(5);
|
||||
c = d;
|
||||
}
|
||||
|
||||
assert(n == 2 && t == 0);
|
||||
}
|
||||
|
||||
struct C2
|
||||
{
|
||||
C1 a, b;
|
||||
|
||||
C2(int x, int y) : a(x), b(y)
|
||||
{}
|
||||
};
|
||||
|
||||
void test_assign_deflt(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C2 c(2, 3);
|
||||
C2 d(5, 10);
|
||||
c = d;
|
||||
}
|
||||
|
||||
assert(n == 4 && t == 0);
|
||||
}
|
||||
|
||||
int k;
|
||||
|
||||
C2 test_ret_v(void)
|
||||
{
|
||||
C2 c(5, 10);
|
||||
return c;
|
||||
}
|
||||
|
||||
C2 & test_ret_r(C2 & r)
|
||||
{
|
||||
return r;
|
||||
}
|
||||
|
||||
void test_assign_return_value(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C2 c(2, 3);
|
||||
c = test_ret_v();
|
||||
}
|
||||
|
||||
assert(n == 6 && t == 0);
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_assign();
|
||||
test_assign_deflt();
|
||||
test_assign_return_value();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int t, n;
|
||||
|
||||
struct C0
|
||||
{
|
||||
int u;
|
||||
|
||||
C0(int a);
|
||||
~C0(void);
|
||||
};
|
||||
|
||||
C0::C0(int a) : u(a)
|
||||
{
|
||||
t += u;
|
||||
n++;
|
||||
}
|
||||
|
||||
C0::~C0(void)
|
||||
{
|
||||
t -= u;
|
||||
}
|
||||
|
||||
struct C1
|
||||
{
|
||||
int u;
|
||||
|
||||
C1(int a);
|
||||
~C1(void);
|
||||
C1(const C1 & c);
|
||||
};
|
||||
|
||||
C1::C1(int a) : u(a)
|
||||
{
|
||||
t += u;
|
||||
n++;
|
||||
}
|
||||
|
||||
C1::~C1(void)
|
||||
{
|
||||
t -= u;
|
||||
}
|
||||
|
||||
C1::C1(const C1 & c) : u(c.u)
|
||||
{
|
||||
t += u;
|
||||
n++;
|
||||
}
|
||||
|
||||
void test_dcopy_init(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C0 x(4);
|
||||
C0 y(x);
|
||||
}
|
||||
|
||||
assert(n == 1 && t == -4);
|
||||
|
||||
t = 0;
|
||||
}
|
||||
|
||||
void test_copy_init(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C1 x(4);
|
||||
C1 y(x);
|
||||
}
|
||||
|
||||
assert(n == 2 && t == 0);
|
||||
}
|
||||
|
||||
struct C2
|
||||
{
|
||||
C1 a, b;
|
||||
|
||||
C2(void);
|
||||
};
|
||||
|
||||
C2::C2(void) : a(1), b(3)
|
||||
{}
|
||||
|
||||
void test_minit(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C2 x;
|
||||
}
|
||||
|
||||
assert(n == 2 && t == 0);
|
||||
}
|
||||
|
||||
void test_minit_copy(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C2 x;
|
||||
C2 y(x);
|
||||
}
|
||||
|
||||
assert(n == 4 && t == 0);
|
||||
}
|
||||
|
||||
int k;
|
||||
|
||||
void test_param_fv(C2 c)
|
||||
{
|
||||
k += c.a.u;
|
||||
}
|
||||
|
||||
void test_param_fr(C2 & c)
|
||||
{
|
||||
k += c.a.u;
|
||||
}
|
||||
|
||||
void test_param_value(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C2 x;
|
||||
test_param_fv(x);
|
||||
}
|
||||
|
||||
assert(n == 4 && t == 0);
|
||||
}
|
||||
|
||||
void test_param_ref(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C2 x;
|
||||
test_param_fr(x);
|
||||
}
|
||||
|
||||
assert(n == 2 && t == 0);
|
||||
}
|
||||
|
||||
C2 test_ret_v(void)
|
||||
{
|
||||
C2 c;
|
||||
return c;
|
||||
}
|
||||
|
||||
C2 & test_ret_r(C2 & r)
|
||||
{
|
||||
return r;
|
||||
}
|
||||
|
||||
void test_return_value(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C2 c(test_ret_v());
|
||||
}
|
||||
|
||||
assert(n == 6 && t == 0);
|
||||
}
|
||||
|
||||
void test_return_reference(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
C2 d;
|
||||
C2 c(test_ret_r(d));
|
||||
}
|
||||
|
||||
assert(n == 2 && t == 0);
|
||||
}
|
||||
|
||||
void test_retparam_value(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
test_param_fv(test_ret_v());
|
||||
}
|
||||
|
||||
assert(n == 6 && t == 0);
|
||||
}
|
||||
|
||||
void test_retparam_reference(void)
|
||||
{
|
||||
n = 0;
|
||||
|
||||
{
|
||||
test_param_fr(test_ret_v());
|
||||
}
|
||||
|
||||
assert(n == 4 && t == 0);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_dcopy_init();
|
||||
test_copy_init();
|
||||
test_minit();
|
||||
test_minit_copy();
|
||||
test_param_value();
|
||||
test_param_ref();
|
||||
test_return_value();
|
||||
test_retparam_value();
|
||||
test_retparam_reference();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
int val(char * c)
|
||||
{
|
||||
return c[0];
|
||||
}
|
||||
|
||||
void set(char * c, int a)
|
||||
{
|
||||
c[0] = a;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0;
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
{
|
||||
char t[10] = {1};
|
||||
sum0 += val(t);
|
||||
sum2 += t[0];
|
||||
set(t, i);
|
||||
sum1 += val(t);
|
||||
sum3 += t[0];
|
||||
}
|
||||
|
||||
return (sum1 - 45) | (sum0 - 10) | (sum3 - 45) | (sum2 - 10);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
|
||||
void copyi(int * a, int * b, int n)
|
||||
{
|
||||
for(int i=0; i<n; i++)
|
||||
b[i] = a[i];
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int t[100], s[100];
|
||||
for(int i=0; i<100; i++)
|
||||
s[i] = i;
|
||||
copyi(s, t, 100);
|
||||
int sum = 0;
|
||||
for(int i=0; i<100; i++)
|
||||
sum += t[i];
|
||||
|
||||
return sum - 4950;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
struct cplx
|
||||
{
|
||||
float r, i;
|
||||
};
|
||||
|
||||
cplx cplx_add(cplx a, cplx b)
|
||||
{
|
||||
cplx c;
|
||||
c.r = a.r + b.r;
|
||||
c.i = a.i + b.i;
|
||||
return c;
|
||||
}
|
||||
|
||||
cplx cplx_sub(cplx a, cplx b)
|
||||
{
|
||||
cplx c;
|
||||
c.r = a.r - b.r;
|
||||
c.i = a.i - b.i;
|
||||
return c;
|
||||
}
|
||||
|
||||
cplx cplx_mul(cplx a, cplx b)
|
||||
{
|
||||
cplx c;
|
||||
c.r = a.r * b.r - a.i * b.i;
|
||||
c.i = a.i * b.r + a.r * b.i;
|
||||
return c;
|
||||
}
|
||||
|
||||
float cplx_abs(cplx a)
|
||||
{
|
||||
return sqrt(a.r * a.r + a.i * a.i);
|
||||
}
|
||||
|
||||
cplx cplx_sum(cplx p, const cplx * a, int n)
|
||||
{
|
||||
cplx s = {0.0, 0.0};
|
||||
cplx c = {1.0, 0.0};
|
||||
|
||||
for(int i=0; i<n; i++)
|
||||
{
|
||||
s = cplx_add(s, cplx_mul(a[i], c));
|
||||
c = cplx_mul(c, p);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
cplx sig[100];
|
||||
|
||||
for(int i=0; i<100; i++)
|
||||
{
|
||||
sig[i].r = cos(i * 1.3);
|
||||
sig[i].i = sin(i * 1.3);
|
||||
}
|
||||
|
||||
cplx c = {1.0, 0.0};
|
||||
float phi = 0.1 * PI;
|
||||
cplx t;
|
||||
t.r = cos(phi); t.i = sin(phi);
|
||||
|
||||
float p[20], q[20];
|
||||
|
||||
for(int i=0; i<20; i++)
|
||||
{
|
||||
p[i] = cplx_abs(cplx_sum(c, sig, 100));
|
||||
c = cplx_mul(c, t);
|
||||
}
|
||||
|
||||
for(int i=0; i<20; i++)
|
||||
{
|
||||
float sumr = 0.0, sumi = 0.0;
|
||||
for(int j=0; j<100; j++)
|
||||
{
|
||||
float co = cos(i * j * 0.1 * PI), si = sin(i * j * 0.1 * PI);
|
||||
sumr += co * sig[j].r - si * sig[j].i;
|
||||
sumi += si * sig[j].r + co * sig[j].i;
|
||||
}
|
||||
q[i] = sqrt(sumr * sumr + sumi * sumi);
|
||||
}
|
||||
#if 1
|
||||
for(int i=0; i<20; i++)
|
||||
{
|
||||
printf("%d, %f - %f\n", i, p[i], q[i]);
|
||||
}
|
||||
#endif
|
||||
for(int i=0; i<20; i++)
|
||||
assert(fabs(p[i] - q[i]) < 1.0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#include <assert.h>
|
||||
|
||||
void check(unsigned long l, unsigned long r)
|
||||
{
|
||||
unsigned long d = l / r, m = l % r;
|
||||
|
||||
assert(d * r + m == l);
|
||||
assert(m < r);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for(char i=0; i<28; i++)
|
||||
{
|
||||
for(char j=0; j<28; j++)
|
||||
{
|
||||
check(0xb3ul << i, 0x2bul << j);
|
||||
check(0xb3ul << i, 0x01ul << j);
|
||||
check(0x01ul << i, 0xc2ul << j);
|
||||
check(0xb31ful << i, 0x2bul << j);
|
||||
check(0xb354ul << i, 0x01ul << j);
|
||||
check(0xb3ul << i, 0x2b1cul << j);
|
||||
check(0xb3ul << i, 0x013ful << j);
|
||||
check(0xb31ful << i, 0x2b23ul << j);
|
||||
check(0xb354ul << i, 0x0145ul << j);
|
||||
check(0xb31f24ul << i, 0x2bul << j);
|
||||
check(0xb35421ul << i, 0x01ul << j);
|
||||
check(0xb31f24ul << i, 0x2b23ul << j);
|
||||
check(0xb35421ul << i, 0x0145ul << j);
|
||||
check(0xb31f24ul << i, 0x2b2356ul << j);
|
||||
check(0xb35421ul << i, 0x0145a7ul << j);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for(unsigned i=0; i<256; i+=11)
|
||||
{
|
||||
for(unsigned j=1; j<256; j++)
|
||||
{
|
||||
unsigned q = i / j, r = i % j;
|
||||
|
||||
assert(q * j + r == i);
|
||||
assert(r >= 0 && r < j);
|
||||
}
|
||||
}
|
||||
|
||||
for(unsigned i=0; i<7000; i+=11)
|
||||
{
|
||||
for(unsigned j=1; j<i; j*=3)
|
||||
{
|
||||
unsigned q = i / j, r = i % j;
|
||||
|
||||
assert(q * j + r == i);
|
||||
assert(r >= 0 && r < j);
|
||||
}
|
||||
}
|
||||
|
||||
for(unsigned i=0; i<64000; i+=121)
|
||||
{
|
||||
for(unsigned j=1; j<i; j*=3)
|
||||
{
|
||||
unsigned q = i / j, r = i % j;
|
||||
|
||||
assert(q * j + r == i);
|
||||
assert(r >= 0 && r < j);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
enum E {
|
||||
e1, e2, e3, e4
|
||||
};
|
||||
|
||||
int check(E e)
|
||||
{
|
||||
switch(e)
|
||||
{
|
||||
case e1:
|
||||
return 10;
|
||||
case e2:
|
||||
return 20;
|
||||
case e3:
|
||||
return 30;
|
||||
default:
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return check(e1) + check(e2) + check(e3) + check(e4) - 160;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int p1(int a, int b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
int p2(int a, int b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
|
||||
int c1(int x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
int c2(int x)
|
||||
{
|
||||
return c1(x);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return p1(5, p2(c2(2), c2(4))) - 13;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
#include <fixmath.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
unsigned tval[] = {
|
||||
1, 2, 16, 128, 255, 256, 4096, 32768, 65535
|
||||
};
|
||||
|
||||
void testmuldiv16u(void)
|
||||
{
|
||||
for (char i=0; i<9; i++)
|
||||
{
|
||||
assert(lmuldiv16u(tval[i], 0, tval[i]) == 0);
|
||||
assert(lmuldiv16u(0, tval[i], tval[i]) == 0);
|
||||
for(char j=0; j<9; j++)
|
||||
{
|
||||
assert(lmuldiv16u(tval[i], tval[j], tval[i]) == tval[j]);
|
||||
assert(lmuldiv16u(tval[j], tval[i], tval[i]) == tval[j]);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0; i<10000; i++)
|
||||
{
|
||||
unsigned a = rand();
|
||||
unsigned b = rand();
|
||||
unsigned c = rand();
|
||||
if (c > 0)
|
||||
{
|
||||
unsigned long d = (unsigned long)a * (unsigned long) b / c;
|
||||
if (d < 0x10000l)
|
||||
assert(lmuldiv16u(a, b, c) == d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned ival[] = {
|
||||
1, 2, 16, 128, 255, 256, 4096, 32767,
|
||||
-1, -2, -16, -128, -255, -256, -4096, -32767
|
||||
};
|
||||
|
||||
void testmuldiv16s(void)
|
||||
{
|
||||
for (char i=0; i<16; i++)
|
||||
{
|
||||
assert(lmuldiv16s(ival[i], 0, ival[i]) == 0);
|
||||
assert(lmuldiv16s(0, ival[i], ival[i]) == 0);
|
||||
for(char j=0; j<16; j++)
|
||||
{
|
||||
assert(lmuldiv16s(ival[i], ival[j], ival[i]) == ival[j]);
|
||||
assert(lmuldiv16s(ival[j], ival[i], ival[i]) == ival[j]);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0; i<10000; i++)
|
||||
{
|
||||
int a = rand();
|
||||
int b = rand();
|
||||
int c = rand();
|
||||
|
||||
if (c > 0)
|
||||
{
|
||||
long d = (long)a * (long)b / c;
|
||||
if (d >= -32768 && d <= 32767)
|
||||
assert(lmuldiv16s(a, b, c) == d);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void testlmul4f12s(void)
|
||||
{
|
||||
for(int i=0; i<20000; i++)
|
||||
{
|
||||
int a = rand();
|
||||
int b = rand();
|
||||
|
||||
long d = ((long)a * (long)b) >> 12;
|
||||
if (d >= -32768 && d <= 32767)
|
||||
assert(lmul4f12s(a, b) == d);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
testlmul4f12s();
|
||||
testmuldiv16u();
|
||||
testmuldiv16s();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
bool feq(float a, float b)
|
||||
{
|
||||
return a == b;
|
||||
}
|
||||
|
||||
bool flt(float a, float b)
|
||||
{
|
||||
return a < b;
|
||||
}
|
||||
|
||||
bool fle(float a, float b)
|
||||
{
|
||||
return a <= b;
|
||||
}
|
||||
|
||||
bool fgt(float a, float b)
|
||||
{
|
||||
return a > b;
|
||||
}
|
||||
|
||||
bool fge(float a, float b)
|
||||
{
|
||||
return a >= b;
|
||||
}
|
||||
|
||||
|
||||
volatile float f;
|
||||
|
||||
inline void cmpflt(float a, float b, bool eq, bool lt, bool gt)
|
||||
{
|
||||
bool le = eq || lt;
|
||||
bool ge = eq || gt;
|
||||
|
||||
assert(feq(a, b) == eq);
|
||||
assert(flt(a, b) == lt);
|
||||
assert(fgt(a, b) == gt);
|
||||
assert(fle(a, b) == le);
|
||||
assert(fge(a, b) == ge);
|
||||
|
||||
f = a;
|
||||
|
||||
assert(feq(f, b) == eq);
|
||||
assert(flt(f, b) == lt);
|
||||
assert(fgt(f, b) == gt);
|
||||
assert(fle(f, b) == le);
|
||||
assert(fge(f, b) == ge);
|
||||
|
||||
f = b;
|
||||
|
||||
assert(feq(a, f) == eq);
|
||||
assert(flt(a, f) == lt);
|
||||
assert(fgt(a, f) == gt);
|
||||
assert(fle(a, f) == le);
|
||||
assert(fge(a, f) == ge);
|
||||
}
|
||||
|
||||
__noinline void test1(void)
|
||||
{
|
||||
cmpflt( 0.0, 1.0, false, true, false);
|
||||
cmpflt( 0.0, -1.0, false, false, true);
|
||||
cmpflt( 1.0, 0.0, false, false, true);
|
||||
cmpflt(-1.0, 0.0, false, true, false);
|
||||
}
|
||||
|
||||
__noinline void test2(void)
|
||||
{
|
||||
cmpflt( 1.0, 1.0, true, false, false);
|
||||
cmpflt( 1.0, 2.0, false, true, false);
|
||||
cmpflt( 2.0, 1.0, false, false, true);
|
||||
}
|
||||
|
||||
__noinline void test3(void)
|
||||
{
|
||||
|
||||
cmpflt(-1.0, -1.0, true, false, false);
|
||||
cmpflt(-1.0, -2.0, false, false, true);
|
||||
cmpflt(-2.0, -1.0, false, true, false);
|
||||
}
|
||||
|
||||
__noinline void test4(void)
|
||||
{
|
||||
|
||||
cmpflt( 1.0, -1.0, false, false, true);
|
||||
cmpflt( 1.0, -2.0, false, false, true);
|
||||
cmpflt( 2.0, -1.0, false, false, true);
|
||||
}
|
||||
|
||||
__noinline void test5(void)
|
||||
{
|
||||
|
||||
cmpflt(-1.0, 1.0, false, true, false);
|
||||
cmpflt(-1.0, 2.0, false, true, false);
|
||||
cmpflt(-2.0, 1.0, false, true, false);
|
||||
}
|
||||
|
||||
__noinline void test6(void)
|
||||
{
|
||||
cmpflt( 0.0, 0.0, true, false, false);
|
||||
cmpflt(-0.0, 0.0, true, false, false);
|
||||
cmpflt( 0.0, -0.0, true, false, false);
|
||||
cmpflt(-0.0, -0.0, true, false, false);
|
||||
}
|
||||
|
||||
__noinline void test7(void)
|
||||
{
|
||||
cmpflt( 1.0, 1.000001, false, true, false);
|
||||
cmpflt( 1.000001, 1.0, false, false, true);
|
||||
cmpflt( 1.000001, 1.000001, true, false, false);
|
||||
}
|
||||
|
||||
__noinline void test8(void)
|
||||
{
|
||||
|
||||
cmpflt( -1.0, -1.000001, false, false, true);
|
||||
cmpflt( -1.000001, -1.0, false, true, false);
|
||||
cmpflt( -1.000001, -1.000001, true, false, false);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
test5();
|
||||
test6();
|
||||
test7();
|
||||
test8();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
float a;
|
||||
int i;
|
||||
long li;
|
||||
unsigned u;
|
||||
unsigned long lu;
|
||||
|
||||
a = 1.0;
|
||||
i = 1;
|
||||
for(int j=0; j<15; j++)
|
||||
{
|
||||
assert(i == (int)a);
|
||||
assert(a == (float)i);
|
||||
a *= 2.0;
|
||||
i <<= 1;
|
||||
}
|
||||
|
||||
a = -1.0;
|
||||
i = -1;
|
||||
for(int j=0; j<15; j++)
|
||||
{
|
||||
assert(i == (int)a);
|
||||
assert(a == (float)i);
|
||||
a *= 2.0;
|
||||
i <<= 1;
|
||||
}
|
||||
|
||||
a = 1.0;
|
||||
i = 1;
|
||||
for(int j=0; j<15; j++)
|
||||
{
|
||||
assert(i == (int)a);
|
||||
assert(a == (float)i);
|
||||
a *= 2.0;
|
||||
a += 1.0;
|
||||
i <<= 1;
|
||||
i += 1;
|
||||
}
|
||||
|
||||
|
||||
a = 1.0;
|
||||
u = 1;
|
||||
for(int j=0; j<16; j++)
|
||||
{
|
||||
assert(u == (unsigned)a);
|
||||
assert(a == (float)u);
|
||||
a *= 2.0;
|
||||
u <<= 1;
|
||||
}
|
||||
|
||||
a = 1.0;
|
||||
u = 1;
|
||||
for(int j=0; j<16; j++)
|
||||
{
|
||||
assert(u == (unsigned)a);
|
||||
assert(a == (float)u);
|
||||
a *= 2.0;
|
||||
a += 1;
|
||||
u <<= 1;
|
||||
u += 1;
|
||||
}
|
||||
|
||||
a = 1.0;
|
||||
li = 1;
|
||||
for(int j=0; j<31; j++)
|
||||
{
|
||||
assert(li == (long)a);
|
||||
assert(a == (float)li);
|
||||
a *= 2.0;
|
||||
li <<= 1;
|
||||
}
|
||||
|
||||
a = -1.0;
|
||||
li = -1;
|
||||
for(int j=0; j<31; j++)
|
||||
{
|
||||
assert(li == (long)a);
|
||||
assert(a == (float)li);
|
||||
a *= 2.0;
|
||||
li <<= 1;
|
||||
}
|
||||
|
||||
a = 1.0;
|
||||
lu = 1;
|
||||
for(int j=0; j<32; j++)
|
||||
{
|
||||
assert(lu == (unsigned long)a);
|
||||
assert(a == (float)lu);
|
||||
a *= 2.0;
|
||||
lu <<= 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
float c = 1.25;
|
||||
float d = 1.0001;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
float a = 0.0;
|
||||
|
||||
for(i=0; i<50; i++)
|
||||
{
|
||||
printf("%d %f %f %f\n", i, i * c, a, i * c - a);
|
||||
assert(i * c == a);
|
||||
a += c;
|
||||
}
|
||||
|
||||
a = d;
|
||||
|
||||
for(i=1; i<50; i++)
|
||||
{
|
||||
printf("%d %f %f %f\n", i, i * d, a, fabs(i * d - a) / i);
|
||||
assert(fabs(i * d - a) < i * 1.0e-6);
|
||||
a += d;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("%f\n", 0.0);
|
||||
|
||||
|
||||
float x = 1.0, y = 1.0;
|
||||
|
||||
char xb[20], yb[20];
|
||||
for(int i=0; i<40; i++)
|
||||
{
|
||||
ftoa(x, xb); float xr = atof(xb);
|
||||
ftoa(y, yb); float yr = atof(yb);
|
||||
|
||||
printf("%20g (%s) %20g : %20g (%s) %20g : %10f %10f \n", x, xb, xr, y, yb, yr, fabs(x - xr) / x, fabs(y - yr) / y);
|
||||
|
||||
if (fabs(x - xr) / x > 0.00001 || fabs(y - yr) / y > 0.00001)
|
||||
return -1;
|
||||
|
||||
x *= 2.5;
|
||||
y *= 0.8;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for(int y=1; y<100; y++)
|
||||
{
|
||||
float fz = 100.0 / (float)y;
|
||||
printf("%d %f %f\n", y, floor(fz * 100.0), fz * 100.0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
int (*funcs[10])(int);
|
||||
|
||||
#assign x 0
|
||||
#repeat
|
||||
int f##x(int i)
|
||||
{
|
||||
return i + x;
|
||||
}
|
||||
#assign x x + 1
|
||||
#until x == 10
|
||||
|
||||
int test(int k)
|
||||
{
|
||||
for(char i=0; i<10; i++)
|
||||
k = funcs[i](k);
|
||||
return k;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#assign x 0
|
||||
#repeat
|
||||
funcs[x] = f##x;
|
||||
#assign x x + 1
|
||||
#until x == 10
|
||||
|
||||
int k = test(-45);
|
||||
return k;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
typedef float (*fop)(float a, float b);
|
||||
|
||||
float fadd(float a, float b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
float fmul(float a, float b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
|
||||
|
||||
struct FNode
|
||||
{
|
||||
FNode * left, * right;
|
||||
float value;
|
||||
fop call;
|
||||
};
|
||||
|
||||
FNode * root;
|
||||
|
||||
float fevalB(FNode * f)
|
||||
{
|
||||
if (f->call)
|
||||
return f->call(fevalB(f->left), fevalB(f->right));
|
||||
else
|
||||
return f->value;
|
||||
}
|
||||
|
||||
float fevalN(FNode * f)
|
||||
{
|
||||
if (f->call)
|
||||
return f->call(fevalN(f->left), fevalN(f->right));
|
||||
else
|
||||
return f->value;
|
||||
}
|
||||
|
||||
#pragma native(fevalN)
|
||||
|
||||
FNode * bop(fop call, FNode * left, FNode * right)
|
||||
{
|
||||
FNode * f = (FNode *)malloc(sizeof(FNode));
|
||||
f->call = call;
|
||||
f->left = left;
|
||||
f->right = right;
|
||||
return f;
|
||||
}
|
||||
|
||||
FNode * bc(float value)
|
||||
{
|
||||
FNode * f = (FNode *)malloc(sizeof(FNode));
|
||||
f->value = value;
|
||||
return f;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
FNode * tree = bop(fadd, bop(fmul, bc(3), bc(5)), bc(6));
|
||||
|
||||
printf("Eval %f, %d\n", fevalB(tree), fevalN(tree));
|
||||
|
||||
assert(fevalB(tree) == 3 * 5 + 6);
|
||||
assert(fevalN(tree) == 3 * 5 + 6);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
|
||||
void incv(int * a, int n)
|
||||
{
|
||||
for(int i=0; i<n; i++)
|
||||
a[i] ++;
|
||||
}
|
||||
|
||||
int t[100];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for(int i=0; i<100; i++)
|
||||
t[i] = i;
|
||||
incv(t, 100);
|
||||
int s = 0;
|
||||
for(int i=0; i<100; i++)
|
||||
s += t[i];
|
||||
|
||||
return s - 5050;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <gfx/bitmap.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
char * const Hires = (char *)0x4000;
|
||||
Bitmap Screen;
|
||||
ClipRect cr = {0, 0, 320, 200};
|
||||
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
bm_init(&Screen, Hires, 40, 25);
|
||||
|
||||
bmu_rect_clear(&Screen, 0, 0, 320, 200);
|
||||
|
||||
bm_line(&Screen, &cr, 0, 0, 199, 199, 0xff, LINOP_SET);
|
||||
|
||||
for(int i=0; i<200; i++)
|
||||
{
|
||||
assert(Hires[(i & 7) + 320 * (i >> 3) + (i & ~7)] == 0x80 >> (i & 7));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <assert.h>
|
||||
|
||||
char a[200], b[200];
|
||||
bool ok = true;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#assign ni 0
|
||||
#repeat
|
||||
a[ni] = ni & 255;
|
||||
#assign ni ni + 1
|
||||
#until ni == 200
|
||||
|
||||
#assign ni 0
|
||||
#repeat
|
||||
if (ok)
|
||||
b[ni] = ni & 255;
|
||||
#assign ni ni + 1
|
||||
#until ni == 200
|
||||
|
||||
int asum = 0, bsum = 0, csum = 0;
|
||||
for(int i=0; i<200; i++)
|
||||
{
|
||||
asum += a[i];
|
||||
bsum += b[i];
|
||||
csum += i & 255;
|
||||
}
|
||||
|
||||
return asum + bsum - 2 * csum;
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
#include <assert.h>
|
||||
|
||||
struct S
|
||||
{
|
||||
int a[100];
|
||||
};
|
||||
|
||||
int lts(S * s)
|
||||
{
|
||||
int x = 0;
|
||||
for(int i=0; i<100; i++)
|
||||
x += s->a[i];
|
||||
return x;
|
||||
}
|
||||
|
||||
int les(S * s)
|
||||
{
|
||||
int x = 0;
|
||||
for(int i=0; i<=99; i++)
|
||||
x += s->a[i];
|
||||
return x;
|
||||
}
|
||||
|
||||
int gts(S * s)
|
||||
{
|
||||
int x = 0;
|
||||
for(int i=100; i>0; i--)
|
||||
x += s->a[i-1];
|
||||
return x;
|
||||
}
|
||||
|
||||
int ges(S * s)
|
||||
{
|
||||
int x = 0;
|
||||
for(int i=99; i>=0; i--)
|
||||
x += s->a[i];
|
||||
return x;
|
||||
}
|
||||
|
||||
int ltu(S * s)
|
||||
{
|
||||
unsigned x = 0;
|
||||
for(int i=0; i<100; i++)
|
||||
x += s->a[i];
|
||||
return x;
|
||||
}
|
||||
|
||||
int leu(S * s)
|
||||
{
|
||||
unsigned x = 0;
|
||||
for(int i=0; i<=99; i++)
|
||||
x += s->a[i];
|
||||
return x;
|
||||
}
|
||||
|
||||
int gtu(S * s)
|
||||
{
|
||||
unsigned x = 0;
|
||||
for(int i=100; i>0; i--)
|
||||
x += s->a[i-1];
|
||||
return x;
|
||||
}
|
||||
|
||||
int geu(S * s)
|
||||
{
|
||||
unsigned x = 0;
|
||||
for(int i=100; i>=1; i--)
|
||||
x += s->a[i-1];
|
||||
return x;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
S s;
|
||||
|
||||
int k = 0;
|
||||
for(int i=0; i<100; i++)
|
||||
{
|
||||
int t = (i & 15) + 3;
|
||||
s.a[i] = t;
|
||||
k += t;
|
||||
}
|
||||
|
||||
assert(lts(&s) == k);
|
||||
assert(les(&s) == k);
|
||||
assert(gts(&s) == k);
|
||||
assert(ges(&s) == k);
|
||||
assert(ltu(&s) == k);
|
||||
assert(leu(&s) == k);
|
||||
assert(gtu(&s) == k);
|
||||
assert(geu(&s) == k);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int a[10][10];
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
{
|
||||
for(int j=0; j<10; j++)
|
||||
{
|
||||
a[i][j] = i + j;
|
||||
}
|
||||
}
|
||||
|
||||
int s = 0;
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
{
|
||||
s += a[i][i];
|
||||
}
|
||||
|
||||
|
||||
assert(s == 90);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,390 @@
|
||||
#include <assert.h>
|
||||
|
||||
void unroll1(void)
|
||||
{
|
||||
int sum0 = 0;
|
||||
int sum2 = 0;
|
||||
int sum3 = 0;
|
||||
int sum10 = 0;
|
||||
int sumfull = 0;
|
||||
|
||||
for(int i=0; i<100; i++)
|
||||
sum0 += i;
|
||||
#pragma unroll(2)
|
||||
for(int i=0; i<100; i++)
|
||||
sum2 += i;
|
||||
#pragma unroll(3)
|
||||
for(int i=0; i<100; i++)
|
||||
sum3 += i;
|
||||
#pragma unroll(10)
|
||||
for(int i=0; i<100; i++)
|
||||
sum10 += i;
|
||||
#pragma unroll(full)
|
||||
for(int i=0; i<100; i++)
|
||||
sumfull += i;
|
||||
assert(sum2 == sum0);
|
||||
assert(sum3 == sum0);
|
||||
assert(sum10 == sum0);
|
||||
assert(sumfull == sum0);
|
||||
}
|
||||
|
||||
void unroll2(void)
|
||||
{
|
||||
int sum0 = 0;
|
||||
int sum2 = 0;
|
||||
int sum3 = 0;
|
||||
int sum10 = 0;
|
||||
int sumfull = 0;
|
||||
|
||||
for(int i=0; i<100; i+=2)
|
||||
sum0 += i;
|
||||
#pragma unroll(2)
|
||||
for(int i=0; i<100; i+=2)
|
||||
sum2 += i;
|
||||
#pragma unroll(3)
|
||||
for(int i=0; i<100; i+=2)
|
||||
sum3 += i;
|
||||
#pragma unroll(10)
|
||||
for(int i=0; i<100; i+=2)
|
||||
sum10 += i;
|
||||
#pragma unroll(full)
|
||||
for(int i=0; i<100; i+=2)
|
||||
sumfull += i;
|
||||
assert(sum2 == sum0);
|
||||
assert(sum3 == sum0);
|
||||
assert(sum10 == sum0);
|
||||
assert(sumfull == sum0);
|
||||
}
|
||||
|
||||
void unroll3(void)
|
||||
{
|
||||
int sum0 = 0;
|
||||
int sum2 = 0;
|
||||
int sum3 = 0;
|
||||
int sum10 = 0;
|
||||
int sumfull = 0;
|
||||
|
||||
for(int i=0; i<100; i+=3)
|
||||
sum0 += i;
|
||||
#pragma unroll(2)
|
||||
for(int i=0; i<100; i+=3)
|
||||
sum2 += i;
|
||||
#pragma unroll(3)
|
||||
for(int i=0; i<100; i+=3)
|
||||
sum3 += i;
|
||||
#pragma unroll(10)
|
||||
for(int i=0; i<100; i+=3)
|
||||
sum10 += i;
|
||||
#pragma unroll(full)
|
||||
for(int i=0; i<100; i+=3)
|
||||
sumfull += i;
|
||||
assert(sum2 == sum0);
|
||||
assert(sum3 == sum0);
|
||||
assert(sum10 == sum0);
|
||||
assert(sumfull == sum0);
|
||||
}
|
||||
|
||||
void unroll50(void)
|
||||
{
|
||||
int sum0 = 0;
|
||||
int sum2 = 0;
|
||||
int sum3 = 0;
|
||||
int sum10 = 0;
|
||||
int sumfull = 0;
|
||||
|
||||
for(int i=0; i<100; i+=50)
|
||||
sum0 += i;
|
||||
#pragma unroll(2)
|
||||
for(int i=0; i<100; i+=50)
|
||||
sum2 += i;
|
||||
#pragma unroll(3)
|
||||
for(int i=0; i<100; i+=50)
|
||||
sum3 += i;
|
||||
#pragma unroll(10)
|
||||
for(int i=0; i<100; i+=50)
|
||||
sum10 += i;
|
||||
#pragma unroll(full)
|
||||
for(int i=0; i<100; i+=50)
|
||||
sumfull += i;
|
||||
assert(sum2 == sum0);
|
||||
assert(sum3 == sum0);
|
||||
assert(sum10 == sum0);
|
||||
assert(sumfull == sum0);
|
||||
}
|
||||
|
||||
void unroll50e(void)
|
||||
{
|
||||
int sum0 = 0;
|
||||
int sum2 = 0;
|
||||
int sum3 = 0;
|
||||
int sum10 = 0;
|
||||
int sumfull = 0;
|
||||
|
||||
for(int i=0; i<=100; i+=50)
|
||||
sum0 += i;
|
||||
#pragma unroll(2)
|
||||
for(int i=0; i<=100; i+=50)
|
||||
sum2 += i;
|
||||
#pragma unroll(3)
|
||||
for(int i=0; i<=100; i+=50)
|
||||
sum3 += i;
|
||||
#pragma unroll(10)
|
||||
for(int i=0; i<=100; i+=50)
|
||||
sum10 += i;
|
||||
#pragma unroll(full)
|
||||
for(int i=0; i<=100; i+=50)
|
||||
sumfull += i;
|
||||
|
||||
assert(sum2 == sum0);
|
||||
assert(sum3 == sum0);
|
||||
assert(sum10 == sum0);
|
||||
assert(sumfull == sum0);
|
||||
}
|
||||
|
||||
void unroll100(void)
|
||||
{
|
||||
int sum0 = 0;
|
||||
int sum2 = 0;
|
||||
int sum3 = 0;
|
||||
int sum10 = 0;
|
||||
int sumfull = 0;
|
||||
|
||||
for(int i=0; i<100; i+=100)
|
||||
sum0 += i;
|
||||
#pragma unroll(2)
|
||||
for(int i=0; i<100; i+=100)
|
||||
sum2 += i;
|
||||
#pragma unroll(3)
|
||||
for(int i=0; i<100; i+=100)
|
||||
sum3 += i;
|
||||
#pragma unroll(10)
|
||||
for(int i=0; i<100; i+=100)
|
||||
sum10 += i;
|
||||
#pragma unroll(full)
|
||||
for(int i=0; i<100; i+=100)
|
||||
sumfull += i;
|
||||
assert(sum2 == sum0);
|
||||
assert(sum3 == sum0);
|
||||
assert(sum10 == sum0);
|
||||
assert(sumfull == sum0);
|
||||
}
|
||||
|
||||
|
||||
void unrolld1(void)
|
||||
{
|
||||
int sum0 = 0;
|
||||
int sum2 = 0;
|
||||
int sum3 = 0;
|
||||
int sum10 = 0;
|
||||
int sumfull = 0;
|
||||
|
||||
for(int i=100; i>0; i--)
|
||||
sum0 += i;
|
||||
#pragma unroll(2)
|
||||
for(int i=100; i>0; i--)
|
||||
sum2 += i;
|
||||
#pragma unroll(3)
|
||||
for(int i=100; i>0; i--)
|
||||
sum3 += i;
|
||||
#pragma unroll(10)
|
||||
for(int i=100; i>0; i--)
|
||||
sum10 += i;
|
||||
#pragma unroll(full)
|
||||
for(int i=100; i>0; i--)
|
||||
sumfull += i;
|
||||
assert(sum2 == sum0);
|
||||
assert(sum3 == sum0);
|
||||
assert(sum10 == sum0);
|
||||
assert(sumfull == sum0);
|
||||
}
|
||||
|
||||
void unrolld2(void)
|
||||
{
|
||||
int sum0 = 0;
|
||||
int sum2 = 0;
|
||||
int sum3 = 0;
|
||||
int sum10 = 0;
|
||||
int sumfull = 0;
|
||||
|
||||
for(int i=100; i>0; i-=2)
|
||||
sum0 += i;
|
||||
#pragma unroll(2)
|
||||
for(int i=100; i>0; i-=2)
|
||||
sum2 += i;
|
||||
#pragma unroll(3)
|
||||
for(int i=100; i>0; i-=2)
|
||||
sum3 += i;
|
||||
#pragma unroll(10)
|
||||
for(int i=100; i>0; i-=2)
|
||||
sum10 += i;
|
||||
#pragma unroll(full)
|
||||
for(int i=100; i>0; i-=2)
|
||||
sumfull += i;
|
||||
assert(sum2 == sum0);
|
||||
assert(sum3 == sum0);
|
||||
assert(sum10 == sum0);
|
||||
assert(sumfull == sum0);
|
||||
}
|
||||
|
||||
void unrolld3(void)
|
||||
{
|
||||
int sum0 = 0;
|
||||
int sum2 = 0;
|
||||
int sum3 = 0;
|
||||
int sum10 = 0;
|
||||
int sumfull = 0;
|
||||
|
||||
for(int i=100; i>0; i-=3)
|
||||
sum0 += i;
|
||||
#pragma unroll(2)
|
||||
for(int i=100; i>0; i-=3)
|
||||
sum2 += i;
|
||||
#pragma unroll(3)
|
||||
for(int i=100; i>0; i-=3)
|
||||
sum3 += i;
|
||||
#pragma unroll(10)
|
||||
for(int i=100; i>0; i-=3)
|
||||
sum10 += i;
|
||||
#pragma unroll(full)
|
||||
for(int i=100; i>0; i-=3)
|
||||
sumfull += i;
|
||||
assert(sum2 == sum0);
|
||||
assert(sum3 == sum0);
|
||||
assert(sum10 == sum0);
|
||||
assert(sumfull == sum0);
|
||||
}
|
||||
|
||||
void unrolld50(void)
|
||||
{
|
||||
int sum0 = 0;
|
||||
int sum2 = 0;
|
||||
int sum3 = 0;
|
||||
int sum10 = 0;
|
||||
int sumfull = 0;
|
||||
|
||||
for(int i=100; i>0; i-=50)
|
||||
sum0 += i;
|
||||
#pragma unroll(2)
|
||||
for(int i=100; i>0; i-=50)
|
||||
sum2 += i;
|
||||
#pragma unroll(3)
|
||||
for(int i=100; i>0; i-=50)
|
||||
sum3 += i;
|
||||
#pragma unroll(10)
|
||||
for(int i=100; i>0; i-=50)
|
||||
sum10 += i;
|
||||
#pragma unroll(full)
|
||||
for(int i=100; i>0; i-=50)
|
||||
sumfull += i;
|
||||
assert(sum2 == sum0);
|
||||
assert(sum3 == sum0);
|
||||
assert(sum10 == sum0);
|
||||
assert(sumfull == sum0);
|
||||
}
|
||||
|
||||
void unrolld50e(void)
|
||||
{
|
||||
int sum0 = 0;
|
||||
int sum2 = 0;
|
||||
int sum3 = 0;
|
||||
int sum10 = 0;
|
||||
int sumfull = 0;
|
||||
|
||||
for(int i=100; i>=0; i-=50)
|
||||
sum0 += i;
|
||||
#pragma unroll(2)
|
||||
for(int i=100; i>=0; i-=50)
|
||||
sum2 += i;
|
||||
#pragma unroll(3)
|
||||
for(int i=100; i>=0; i-=50)
|
||||
sum3 += i;
|
||||
#pragma unroll(10)
|
||||
for(int i=100; i>=0; i-=50)
|
||||
sum10 += i;
|
||||
#pragma unroll(full)
|
||||
for(int i=100; i>=0; i-=50)
|
||||
sumfull += i;
|
||||
assert(sum2 == sum0);
|
||||
assert(sum3 == sum0);
|
||||
assert(sum10 == sum0);
|
||||
assert(sumfull == sum0);
|
||||
}
|
||||
|
||||
void unrolld100(void)
|
||||
{
|
||||
int sum0 = 0;
|
||||
int sum2 = 0;
|
||||
int sum3 = 0;
|
||||
int sum10 = 0;
|
||||
int sumfull = 0;
|
||||
|
||||
for(int i=100; i>0; i-=100)
|
||||
sum0 += i;
|
||||
#pragma unroll(2)
|
||||
for(int i=100; i>0; i-=100)
|
||||
sum2 += i;
|
||||
#pragma unroll(3)
|
||||
for(int i=100; i>0; i-=100)
|
||||
sum3 += i;
|
||||
#pragma unroll(10)
|
||||
for(int i=100; i>0; i-=100)
|
||||
sum10 += i;
|
||||
#pragma unroll(full)
|
||||
for(int i=100; i>0; i-=100)
|
||||
sumfull += i;
|
||||
assert(sum2 == sum0);
|
||||
assert(sum3 == sum0);
|
||||
assert(sum10 == sum0);
|
||||
assert(sumfull == sum0);
|
||||
}
|
||||
|
||||
|
||||
char glob[20];
|
||||
|
||||
void autounroll(void)
|
||||
{
|
||||
char sum0 = 0;
|
||||
char sum1 = 0;
|
||||
char sum2 = 0;
|
||||
char sum3 = 0;
|
||||
char sum4 = 0;
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
sum0 += glob[i];
|
||||
// for(int i=10; i<20; i++)
|
||||
// sum1 += glob[i - 10];
|
||||
for(int i=10; i>0; i--)
|
||||
sum2 += glob[i - 1];
|
||||
for(int i=9; i>=0; i--)
|
||||
sum3 += glob[i];
|
||||
// for(int i=0; i<=9; i++)
|
||||
// sum4 += glob[i];
|
||||
|
||||
// assert(sum1 == sum0);
|
||||
assert(sum2 == sum0);
|
||||
#if 0
|
||||
assert(sum3 == sum0);
|
||||
assert(sum4 == sum0);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for(int i=0; i<20; i++)
|
||||
glob[i] = i;
|
||||
#if 0
|
||||
unroll1();
|
||||
unroll2();
|
||||
unroll3();
|
||||
unroll50();
|
||||
unroll50e();
|
||||
unroll100();
|
||||
unrolld1();
|
||||
unrolld2();
|
||||
unrolld3();
|
||||
unrolld50();
|
||||
unrolld50e();
|
||||
unrolld100();
|
||||
#endif
|
||||
autounroll();
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
SRCS=$(filter-out ambiguousoverload_trigger.c opp_part1.cpp opp_part2.cpp, $(wildcard *.c *.cpp))
|
||||
EXES=$(patsubst %.c,%,$(SRCS))
|
||||
EXES:=$(patsubst %.cpp,%,$(EXES))
|
||||
|
||||
all: $(EXES)
|
||||
|
||||
%: %.c
|
||||
$(OSCAR64_CC) -ea -g -bc $<
|
||||
$(OSCAR64_CC) -ea -g -n $<
|
||||
$(OSCAR64_CC) -ea -g -O2 -bc $<
|
||||
$(OSCAR64_CC) -ea -g -O2 -n $<
|
||||
$(OSCAR64_CC) -ea -g -O0 -bc $<
|
||||
$(OSCAR64_CC) -ea -g -O0 -n $<
|
||||
$(OSCAR64_CC) -ea -g -Os -bc $<
|
||||
$(OSCAR64_CC) -ea -g -Os -n $<
|
||||
$(OSCAR64_CC) -ea -g -O3 -bc $<
|
||||
$(OSCAR64_CC) -ea -g -O3 -n $<
|
||||
|
||||
%: %.cpp
|
||||
$(OSCAR64_CXX) -ea -g -bc $<
|
||||
$(OSCAR64_CXX) -ea -g -n $<
|
||||
$(OSCAR64_CXX) -ea -g -O2 -bc $<
|
||||
$(OSCAR64_CXX) -ea -g -O2 -n $<
|
||||
$(OSCAR64_CXX) -ea -g -O0 -bc $<
|
||||
$(OSCAR64_CXX) -ea -g -O0 -n $<
|
||||
$(OSCAR64_CXX) -ea -g -Os -bc $<
|
||||
$(OSCAR64_CXX) -ea -g -Os -n $<
|
||||
$(OSCAR64_CXX) -ea -g -O3 -bc $<
|
||||
$(OSCAR64_CXX) -ea -g -O3 -n $<
|
||||
|
||||
# testb
|
||||
bitshifttest: bitshifttest.c
|
||||
$(OSCAR64_CC) -ea -g -bc $<
|
||||
$(OSCAR64_CC) -ea -g -bc -O2 $<
|
||||
$(OSCAR64_CC) -ea -g -bc -O0 $<
|
||||
$(OSCAR64_CC) -ea -g -bc -Os $<
|
||||
$(OSCAR64_CC) -ea -g -bc -O3 $<
|
||||
$(OSCAR64_CC) -ea -g -n $<
|
||||
|
||||
# testn
|
||||
stripedarraytest: stripedarraytest.c
|
||||
$(OSCAR64_CC) -ea -g -n $<
|
||||
$(OSCAR64_CC) -ea -g -O2 -n $<
|
||||
$(OSCAR64_CC) -ea -g -O0 -n $<
|
||||
$(OSCAR64_CC) -ea -g -Os -n $<
|
||||
$(OSCAR64_CC) -ea -g -O3 -n $<
|
||||
|
||||
stripedstructtest: stripedstructtest.c
|
||||
$(OSCAR64_CC) -ea -g -n $<
|
||||
$(OSCAR64_CC) -ea -g -O2 -n $<
|
||||
$(OSCAR64_CC) -ea -g -O0 -n $<
|
||||
$(OSCAR64_CC) -ea -g -Os -n $<
|
||||
$(OSCAR64_CC) -ea -g -O3 -n $<
|
||||
|
||||
autorefreturn: autorefreturn.cpp
|
||||
$(OSCAR64_CC) -ea -g -n $<
|
||||
$(OSCAR64_CC) -ea -g -O2 -n $<
|
||||
$(OSCAR64_CC) -ea -g -O0 -n $<
|
||||
$(OSCAR64_CC) -ea -g -Os -n $<
|
||||
$(OSCAR64_CC) -ea -g -O3 -n $<
|
||||
|
||||
copyconstructor: copyconstructor.cpp
|
||||
$(OSCAR64_CC) -ea -g -n $<
|
||||
$(OSCAR64_CC) -ea -g -O2 -n $<
|
||||
$(OSCAR64_CC) -ea -g -O0 -n $<
|
||||
$(OSCAR64_CC) -ea -g -Os -n $<
|
||||
$(OSCAR64_CC) -ea -g -O3 -n $<
|
||||
|
||||
andmultest: andmultest.cpp
|
||||
$(OSCAR64_CC) -ea -g -n $<
|
||||
$(OSCAR64_CC) -ea -g -O2 -n $<
|
||||
$(OSCAR64_CC) -ea -g -O0 -n $<
|
||||
$(OSCAR64_CC) -ea -g -Os -n $<
|
||||
$(OSCAR64_CC) -ea -g -O3 -n $<
|
||||
|
||||
# testi
|
||||
volatiletest: volatiletest.c
|
||||
$(OSCAR64_CC) -eai -g -n $<
|
||||
$(OSCAR64_CC) -eai -g -O2 -n $<
|
||||
$(OSCAR64_CC) -eai -g -O0 -n $<
|
||||
$(OSCAR64_CC) -eai -g -Os -n $<
|
||||
$(OSCAR64_CC) -eai -g -O3 -n $<
|
||||
|
||||
variadic-macros: variadic_macros.c
|
||||
$(OSCAR64_CC) -eai -g -n $<
|
||||
$(OSCAR64_CC) -eai -g -O2 -n $<
|
||||
$(OSCAR64_CC) -eai -g -O0 -n $<
|
||||
$(OSCAR64_CC) -eai -g -Os -n $<
|
||||
$(OSCAR64_CC) -eai -g -O3 -n $<
|
||||
|
||||
clean:
|
||||
@$(RM) *.asm *.bcs *.int *.lbl *.map *.prg
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
|
||||
void check_byte(char a)
|
||||
{
|
||||
char b1[8] = {0}, n1[8] = {0}, b0[8] = {0}, n0[8] = {0};
|
||||
|
||||
#for(i, 8) if ((a & (1 << i)) == (1 << i)) b1[i]++;
|
||||
#for(i, 8) if ((a & (1 << i)) != (1 << i)) n1[i]++;
|
||||
#for(i, 8) if ((a & (1 << i)) == 0) b0[i]++;
|
||||
#for(i, 8) if ((a & (1 << i)) != 0) n0[i]++;
|
||||
|
||||
for(char i=0; i<8; i++)
|
||||
{
|
||||
assert(b0[i] == n1[i]);
|
||||
assert(b1[i] == n0[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for(int i=0; i<256; i++)
|
||||
check_byte(i);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for(int i=0; i<1000; i++)
|
||||
{
|
||||
float w = 0.0123 * i;
|
||||
float co = cos(w), si = sin(w);
|
||||
|
||||
float r = co * co + si * si;
|
||||
|
||||
assert(fabs(r - 1) < 0.001);
|
||||
|
||||
assert(fabs(sqrt(w * w) - w) < 0.001);
|
||||
|
||||
float aw = atan2(si, co);
|
||||
|
||||
float co2 = cos(aw), si2 = sin(aw);
|
||||
|
||||
assert(fabs(co2 - co) < 0.001);
|
||||
assert(fabs(si2 - si) < 0.001);
|
||||
|
||||
float ex = exp(w), em = exp(-w);
|
||||
|
||||
assert(fabs(log(ex) - w) < 0.001);
|
||||
assert(fabs(log(em) + w) < 0.001);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char testmem[2000];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Test memchr with basic functionality
|
||||
assert(memcmp(memchr("hello", 'h', 5), "hello", 5) == 0);
|
||||
assert(memcmp(memchr("hello", 'e', 5), "ello", 4) == 0);
|
||||
assert(memcmp(memchr("hello", 'l', 5), "llo", 3) == 0); // finds first 'l'
|
||||
assert(memcmp(memchr("hello", 'o', 5), "o", 1) == 0);
|
||||
assert(memchr("hello", 'x', 5) == 0);
|
||||
|
||||
// Test memchr with size limits
|
||||
assert(memchr("hello", 'o', 4) == 0); // 'o' is at position 4, but size is 4 (0-3)
|
||||
assert(memcmp(memchr("hello", 'l', 3), "llo", 3) == 0); // finds 'l' at position 2 within size 3
|
||||
assert(memchr("hello", 'e', 1) == 0); // 'e' is at position 1, but size is 1 (0 only)
|
||||
|
||||
// Test memchr with zero size
|
||||
assert(memchr("hello", 'h', 0) == 0);
|
||||
assert(memchr("hello", 'x', 0) == 0);
|
||||
|
||||
// Test memchr with null character
|
||||
assert(*((char*)memchr("hello", '\0', 6)) == '\0'); // finds null terminator
|
||||
assert(memchr("hello", '\0', 5) == 0); // null is at position 5, size is 5 (0-4)
|
||||
|
||||
// Test memchr with single byte
|
||||
assert(memcmp(memchr("a", 'a', 1), "a", 1) == 0);
|
||||
assert(memchr("a", 'b', 1) == 0);
|
||||
|
||||
// Test memchr with repeated characters
|
||||
assert(memcmp(memchr("aaaaaa", 'a', 6), "aaaaaa", 6) == 0); // finds first occurrence
|
||||
assert(memcmp(memchr("abcabc", 'a', 6), "abcabc", 6) == 0); // finds first 'a'
|
||||
assert(memcmp(memchr("abcabc", 'b', 6), "bcabc", 5) == 0); // finds first 'b'
|
||||
assert(memcmp(memchr("abcabc", 'c', 6), "cabc", 4) == 0); // finds first 'c'
|
||||
|
||||
// Test memchr with special characters and binary data
|
||||
assert(memcmp(memchr("hello world", ' ', 11), " world", 6) == 0);
|
||||
assert(memcmp(memchr("a.b,c;d", '.', 7), ".b,c;d", 6) == 0);
|
||||
assert(memcmp(memchr("a.b,c;d", ',', 7), ",c;d", 4) == 0);
|
||||
assert(memcmp(memchr("a.b,c;d", ';', 7), ";d", 2) == 0);
|
||||
|
||||
// Test memchr with binary data (including zeros)
|
||||
testmem[0] = 'a';
|
||||
testmem[1] = '\0';
|
||||
testmem[2] = 'b';
|
||||
testmem[3] = '\0';
|
||||
testmem[4] = 'c';
|
||||
|
||||
assert(memchr(testmem, 'a', 5) == testmem);
|
||||
assert(memchr(testmem, '\0', 5) == testmem + 1); // finds first null
|
||||
assert(memchr(testmem, 'b', 5) == testmem + 2);
|
||||
assert(memchr(testmem, 'c', 5) == testmem + 4);
|
||||
assert(memchr(testmem, 'd', 5) == 0);
|
||||
|
||||
// Test memchr with different byte values
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
testmem[i] = (unsigned char)i;
|
||||
}
|
||||
|
||||
// Test finding various byte values
|
||||
assert(memchr(testmem, 0, 256) == testmem); // byte 0 at position 0
|
||||
assert(memchr(testmem, 1, 256) == testmem + 1); // byte 1 at position 1
|
||||
assert(memchr(testmem, 127, 256) == testmem + 127); // byte 127 at position 127
|
||||
assert(memchr(testmem, 255, 256) == testmem + 255); // byte 255 at position 255
|
||||
|
||||
// Test memchr with size smaller than target position
|
||||
assert(memchr(testmem, 100, 50) == 0); // byte 100 is at position 100, but size is 50
|
||||
assert(memchr(testmem, 100, 101) == testmem + 100); // finds it with adequate size
|
||||
|
||||
// Test memchr with longer memory region
|
||||
for(int i = 0; i < 1000; i++)
|
||||
{
|
||||
testmem[i] = 'a' + (i & 7);
|
||||
}
|
||||
|
||||
// Test memchr with pattern
|
||||
assert(memchr(testmem, 'a', 1000) == testmem); // first 'a' at start
|
||||
assert(memchr(testmem, 'b', 1000) == testmem + 1); // first 'b' at position 1
|
||||
assert(memchr(testmem, 'h', 1000) == testmem + 7); // first 'h' at position 7
|
||||
assert(memchr(testmem, 'z', 1000) == 0); // 'z' not in pattern
|
||||
|
||||
// Test memchr starting from middle of buffer
|
||||
assert(memchr(testmem + 100, 'a', 900) == testmem + 104); // next 'a' after position 100
|
||||
assert(memchr(testmem + 100, 'c', 900) == testmem + 106); // next 'c' after position 100
|
||||
|
||||
// Test memchr with exact size to find character
|
||||
assert(memchr(testmem, 'h', 8) == testmem + 7); // 'h' at position 7, size exactly 8
|
||||
assert(memchr(testmem, 'h', 7) == 0); // 'h' at position 7, size only 7 (0-6)
|
||||
|
||||
// Test memchr character not found in range
|
||||
for(int i = 0; i < 100; i++)
|
||||
{
|
||||
testmem[i] = 'x'; // fill with 'x'
|
||||
}
|
||||
assert(memchr(testmem, 'y', 100) == 0); // 'y' not found
|
||||
assert(memchr(testmem, 'x', 100) == testmem); // 'x' found at start
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
unsigned b[4096];
|
||||
|
||||
void testfwd(unsigned sz)
|
||||
{
|
||||
for(unsigned i=0; i<4096; i++)
|
||||
b[i] = i;
|
||||
|
||||
memmove(b + 100, b + 101, 2 * sz);
|
||||
|
||||
for(unsigned i=0; i<100; i++)
|
||||
assert(b[i] == i);
|
||||
for(unsigned i=100; i<100 + sz; i++)
|
||||
assert(b[i] == i + 1);
|
||||
for(unsigned i=100 + sz; i<4096; i++)
|
||||
assert(b[i] == i);
|
||||
}
|
||||
|
||||
void testback(unsigned sz)
|
||||
{
|
||||
for(unsigned i=0; i<4096; i++)
|
||||
b[i] = i;
|
||||
|
||||
memmove(b + 101, b + 100, 2 * sz);
|
||||
|
||||
for(unsigned i=0; i<101; i++)
|
||||
assert(b[i] == i);
|
||||
for(unsigned i=101; i<101 + sz; i++)
|
||||
assert(b[i] == i - 1);
|
||||
for(unsigned i=101 + sz; i<4096; i++)
|
||||
assert(b[i] == i);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for(unsigned i=1; i<2048; i *= 2)
|
||||
{
|
||||
testfwd(i - 1);
|
||||
testfwd(i);
|
||||
testback(i);
|
||||
testback(i - 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned n1, n0;
|
||||
|
||||
n1 = 0; n0 = 0;
|
||||
for(int i=-1000; i<2000; i+=37)
|
||||
{
|
||||
for(char j=0; j<255; j++)
|
||||
{
|
||||
if (i < j)
|
||||
n1++;
|
||||
else
|
||||
n0++;
|
||||
}
|
||||
}
|
||||
|
||||
assert(n1 == 7893 && n0 == 13017);
|
||||
|
||||
n1 = 0; n0 = 0;
|
||||
for(int i=-1000; i<2000; i+=37)
|
||||
{
|
||||
for(char j=0; j<255; j++)
|
||||
{
|
||||
if (i <= j)
|
||||
n1++;
|
||||
else
|
||||
n0++;
|
||||
}
|
||||
}
|
||||
|
||||
assert(n1 == 7899 && n0 == 13011);
|
||||
|
||||
n1 = 0; n0 = 0;
|
||||
for(int i=-1000; i<2000; i+=37)
|
||||
{
|
||||
for(char j=0; j<255; j++)
|
||||
{
|
||||
if (i >= j)
|
||||
n1++;
|
||||
else
|
||||
n0++;
|
||||
}
|
||||
}
|
||||
|
||||
assert(n0 == 7893 && n1 == 13017);
|
||||
|
||||
n1 = 0; n0 = 0;
|
||||
for(int i=-1000; i<2000; i+=37)
|
||||
{
|
||||
for(char j=0; j<255; j++)
|
||||
{
|
||||
if (i > j)
|
||||
n1++;
|
||||
else
|
||||
n0++;
|
||||
}
|
||||
}
|
||||
|
||||
assert(n0 == 7899 && n1 == 13011);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#include <gfx/vector3d.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
Matrix4 ml, mr;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for(char i=0; i<16; i++)
|
||||
{
|
||||
for(char j=0; j<16; j++)
|
||||
{
|
||||
for(char k=0; k<16; k++)
|
||||
{
|
||||
ml.m[k] = (i == k) ? 1.0 : 0.0;
|
||||
mr.m[k] = (j == k) ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
mat4_mmul(&ml, &mr);
|
||||
|
||||
#if 0
|
||||
printf("%d, %d\n", i, j);
|
||||
for(char k=0; k<16; k++)
|
||||
printf("%f ", ml.m[k]);
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
for(char k=0; k<16; k++)
|
||||
{
|
||||
char ix = i & 3, iy = i >> 2;
|
||||
char jx = j & 3, jy = j >> 2;
|
||||
char kx = k & 3, ky = k >> 2;
|
||||
|
||||
if (ky == jy && kx == ix && jx == iy)
|
||||
assert(ml.m[k] == 1.0);
|
||||
else
|
||||
assert(ml.m[k] == 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
#include <assert.h>
|
||||
|
||||
struct A
|
||||
{
|
||||
int n;
|
||||
|
||||
A(int n_)
|
||||
: n(n_) {}
|
||||
|
||||
A(const A & a)
|
||||
: n(a.n) {}
|
||||
|
||||
A operator+(const A & a) const
|
||||
{
|
||||
return A(n + a.n);
|
||||
}
|
||||
|
||||
A operator-(const A & a) const
|
||||
{
|
||||
return A(n - a.n);
|
||||
}
|
||||
|
||||
A & operator+=(const A & a)
|
||||
{
|
||||
n += a.n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
A & operator-=(const A & a)
|
||||
{
|
||||
n -= a.n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
A operator-(void) const
|
||||
{
|
||||
return A(-n);
|
||||
}
|
||||
|
||||
A & operator++(void)
|
||||
{
|
||||
n++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
A & operator--(void)
|
||||
{
|
||||
n--;
|
||||
return *this;
|
||||
}
|
||||
|
||||
A operator++(int);
|
||||
|
||||
A operator--(int);
|
||||
|
||||
};
|
||||
|
||||
A A::operator++(int)
|
||||
{
|
||||
A a(*this);
|
||||
n++;
|
||||
return a;
|
||||
}
|
||||
|
||||
A A::operator--(int)
|
||||
{
|
||||
A a(*this);
|
||||
n--;
|
||||
return a;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
A a(7), b(8), c(9);
|
||||
|
||||
assert((++a).n == 8);
|
||||
assert(a.n == 8);
|
||||
|
||||
assert((--a).n == 7);
|
||||
assert(a.n == 7);
|
||||
|
||||
assert((a++).n == 7);
|
||||
assert(a.n == 8);
|
||||
assert((a--).n == 8);
|
||||
assert(a.n == 7);
|
||||
|
||||
assert((a + b - c + -a + -b - -c).n == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <opp/array.h>
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
opp::array<int, 10> a10;
|
||||
opp::array<int, 20> a20;
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
a10[i] = i;
|
||||
for(int i=0; i<20; i++)
|
||||
a20[i] = i;
|
||||
|
||||
int s = 0;
|
||||
for(int i=0; i<10; i++)
|
||||
s += a10[i];
|
||||
for(int i=10; i<20; i++)
|
||||
s -= a20[i];
|
||||
|
||||
assert(s == -100);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <opp/functional.h>
|
||||
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
virtual int eval(void) const = 0;
|
||||
};
|
||||
|
||||
class ConstNode : public Node
|
||||
{
|
||||
private:
|
||||
int v;
|
||||
public:
|
||||
ConstNode(int v_) : v(v_) {}
|
||||
virtual int eval(void) const
|
||||
{
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
class BinaryNode : public Node
|
||||
{
|
||||
private:
|
||||
opp::function<int(int, int)> op;
|
||||
Node * left, * right;
|
||||
public:
|
||||
BinaryNode(opp::function<int(int, int)> op_, Node * left_, Node * right_);
|
||||
|
||||
virtual int eval(void) const
|
||||
{
|
||||
return op(left->eval(), right->eval());
|
||||
}
|
||||
};
|
||||
|
||||
inline BinaryNode::BinaryNode(opp::function<int(int, int)> op_, Node * left_, Node * right_)
|
||||
: op(op_), left(left_), right(right_) {}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Node * s1 =
|
||||
new BinaryNode([=](int a, int b){return a + b;},
|
||||
new ConstNode(7), new ConstNode(11)
|
||||
);
|
||||
|
||||
return s1->eval() - 18;
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
#include <opp/string.h>
|
||||
#include <opp/hashmap.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void test_int_int(void)
|
||||
{
|
||||
opp::hashmap<int, long> hm;
|
||||
for(int i=0; i<100; i++)
|
||||
hm.at(i) = (long)i * (long)i;
|
||||
|
||||
int sum = 0;
|
||||
for(auto [k, v] : hm)
|
||||
{
|
||||
sum += k;
|
||||
assert(v == (long)k * (long)k);
|
||||
}
|
||||
assert(sum == 4950);
|
||||
|
||||
auto it = hm.begin();
|
||||
while (it != hm.end())
|
||||
{
|
||||
if (it->key & 1)
|
||||
it = hm.erase(it);
|
||||
else
|
||||
it++;
|
||||
}
|
||||
|
||||
sum = 0;
|
||||
for(auto [k, v] : hm)
|
||||
{
|
||||
sum += k;
|
||||
assert(v == (long)k * (long)k);
|
||||
}
|
||||
assert(sum == 2450);
|
||||
|
||||
sum = 0;
|
||||
for(int i=0; i<100; i++)
|
||||
{
|
||||
auto it = hm.find(i);
|
||||
if (it != hm.end())
|
||||
{
|
||||
assert(it->value == (long)it->key * (long)it->key);
|
||||
sum += it->key;
|
||||
}
|
||||
}
|
||||
assert(sum == 2450);
|
||||
}
|
||||
|
||||
void test_string_string(void)
|
||||
{
|
||||
opp::hashmap<opp::string, opp::string> hm;
|
||||
for(int i=0; i<100; i++)
|
||||
hm.at(opp::to_string(i)) = opp::to_string((long)i * (long)i);
|
||||
|
||||
int sum = 0;
|
||||
for(auto [k, v] : hm)
|
||||
{
|
||||
long l = v.to_long();
|
||||
int i = k.to_int();
|
||||
sum += i;
|
||||
assert(l == (long)i * (long)i);
|
||||
}
|
||||
assert(sum == 4950);
|
||||
|
||||
auto it = hm.begin();
|
||||
while (it != hm.end())
|
||||
{
|
||||
long i = it->key.to_int();
|
||||
if (i & 1)
|
||||
it = hm.erase(it);
|
||||
else
|
||||
it++;
|
||||
}
|
||||
|
||||
sum = 0;
|
||||
for(auto [k, v] : hm)
|
||||
{
|
||||
long l = v.to_long();
|
||||
long i = k.to_int();
|
||||
sum += i;
|
||||
assert(l == (long)i * (long)i);
|
||||
}
|
||||
assert(sum == 2450);
|
||||
|
||||
sum = 0;
|
||||
for(int i=0; i<100; i++)
|
||||
{
|
||||
auto it = hm.find(opp::to_string(i));
|
||||
if (it != hm.end())
|
||||
{
|
||||
long l = it->value.to_long();
|
||||
long k = it->key.to_int();
|
||||
assert(l == (long)k * (long)k);
|
||||
sum += k;
|
||||
}
|
||||
}
|
||||
assert(sum == 2450);
|
||||
}
|
||||
|
||||
void test_int_string(void)
|
||||
{
|
||||
opp::hashmap<int, opp::string> hm;
|
||||
for(int i=0; i<100; i++)
|
||||
hm.at(i) = opp::to_string((long)i * (long)i);
|
||||
|
||||
int sum = 0;
|
||||
for(auto [k, v] : hm)
|
||||
{
|
||||
sum += k;
|
||||
long l = v.to_long();
|
||||
assert(l == (long)k * (long)k);
|
||||
}
|
||||
assert(sum == 4950);
|
||||
|
||||
auto it = hm.begin();
|
||||
while (it != hm.end())
|
||||
{
|
||||
if (it->key & 1)
|
||||
it = hm.erase(it);
|
||||
else
|
||||
it++;
|
||||
}
|
||||
|
||||
sum = 0;
|
||||
for(auto [k, v] : hm)
|
||||
{
|
||||
sum += k;
|
||||
long l = v.to_long();
|
||||
assert(l == (long)k * (long)k);
|
||||
}
|
||||
assert(sum == 2450);
|
||||
|
||||
sum = 0;
|
||||
for(int i=0; i<100; i++)
|
||||
{
|
||||
auto it = hm.find(i);
|
||||
if (it != hm.end())
|
||||
{
|
||||
long l = it->value.to_long();
|
||||
assert(l == (long)it->key * (long)it->key);
|
||||
sum += it->key;
|
||||
}
|
||||
}
|
||||
assert(sum == 2450);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_int_int();
|
||||
test_int_string();
|
||||
test_string_string();
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <opp/list.h>
|
||||
#include <opp/algorithm.h>
|
||||
#include <assert.h>
|
||||
#include <opp/iostream.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
opp::list<int> a;
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
a.push_back(i);
|
||||
|
||||
int s = 0;
|
||||
for(auto i : a)
|
||||
s += i;
|
||||
|
||||
assert(s == 45);
|
||||
|
||||
auto li = a.begin();
|
||||
for(int i=0; i<5; i++)
|
||||
{
|
||||
li = a.erase(li);
|
||||
li++;
|
||||
}
|
||||
|
||||
s = 0;
|
||||
for(auto i : a)
|
||||
s += i;
|
||||
|
||||
assert(s == 1 + 3 + 5 + 7 + 9);
|
||||
|
||||
opp::list<int> b;
|
||||
|
||||
b = a;
|
||||
|
||||
s = 0;
|
||||
for(auto i : b)
|
||||
s += i;
|
||||
|
||||
assert(s == 1 + 3 + 5 + 7 + 9);
|
||||
|
||||
opp::list<int> c = opp::list<int>(b);
|
||||
|
||||
s = 0;
|
||||
for(auto i : c)
|
||||
s += i;
|
||||
|
||||
assert(s == 1 + 3 + 5 + 7 + 9);
|
||||
|
||||
s = 0;
|
||||
for(auto i : b)
|
||||
s += i;
|
||||
|
||||
assert(s == 1 + 3 + 5 + 7 + 9);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#include <assert.h>
|
||||
#include <opp/numeric.h>
|
||||
#include <opp/string.h>
|
||||
#include <opp/iterator.h>
|
||||
#include <opp/array.h>
|
||||
#include <opp/sstream.h>
|
||||
#include <opp/utility.h>
|
||||
|
||||
using opp::string, opp::cout;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
opp::array<int, 10> v;
|
||||
|
||||
opp::iota(v.begin(), v.end(), 10);
|
||||
|
||||
string s = opp::accumulate(
|
||||
opp::next(v.begin()), v.end(), opp::to_string(v[0]),
|
||||
[](const opp::string & ws, int k) {return ws + "-" + opp::to_string(k);});
|
||||
|
||||
assert(s == "10-11-12-13-14-15-16-17-18-19");
|
||||
|
||||
opp::ostringstream osstr;
|
||||
opp::inclusive_scan(v.begin(), v.end(), opp::ostream_iterator<int>(osstr, ", "));
|
||||
assert(osstr.str() == "10, 21, 33, 46, 60, 75, 91, 108, 126, 145, ");
|
||||
|
||||
osstr.str("");
|
||||
opp::exclusive_scan(v.begin(), v.end(), opp::ostream_iterator<int>(osstr, ", "), 0);
|
||||
assert(osstr.str() == "0, 10, 21, 33, 46, 60, 75, 91, 108, 126, ");
|
||||
|
||||
opp::array<int, 10> w;
|
||||
|
||||
opp::iota(w.begin(), w.end(), 1);
|
||||
|
||||
assert(opp::inner_product(v.begin(), v.end(), w.begin(), 0) == 880);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#include <opp/optional.h>
|
||||
#include <opp/string.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <opp/optional.h>
|
||||
#include <opp/string.h>
|
||||
|
||||
using opp::optional;
|
||||
using opp::string;
|
||||
|
||||
optional<int> isqrt(int i)
|
||||
{
|
||||
if (i < 0)
|
||||
return optional<int>();
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
optional<string> ssqrt(int i)
|
||||
{
|
||||
if (i < 0)
|
||||
return optional<string>();
|
||||
else
|
||||
return opp::to_string(i);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int sum = 0;
|
||||
for(int i=-10; i<=10; i++)
|
||||
{
|
||||
for (auto s : isqrt(i))
|
||||
sum += s;
|
||||
}
|
||||
assert(sum == 55);
|
||||
|
||||
sum = 0;
|
||||
for(int i=-10; i<=10; i++)
|
||||
{
|
||||
if (auto s = ssqrt(i))
|
||||
sum += s->to_int();
|
||||
}
|
||||
assert(sum == 55);
|
||||
|
||||
sum = 0;
|
||||
for(int i=-10; i<=10; i++)
|
||||
{
|
||||
for (auto s : ssqrt(i))
|
||||
sum += s.to_int();
|
||||
}
|
||||
assert(sum == 55);
|
||||
|
||||
sum = 0;
|
||||
for(int i=-10; i<=10; i++)
|
||||
{
|
||||
auto s = ssqrt(i);
|
||||
auto t = s;
|
||||
|
||||
if (t)
|
||||
sum += t->to_int();
|
||||
}
|
||||
assert(sum == 55);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <assert.h>
|
||||
#include <opp/vector.h>
|
||||
#include <opp/utility.h>
|
||||
#include <opp/iostream.h>
|
||||
|
||||
using namespace opp;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
vector<pair<int, int> > vii;
|
||||
|
||||
for(int i=0; i<100; i++)
|
||||
vii.push_back(make_pair(i, i * i));
|
||||
|
||||
int sum1 = 0;
|
||||
long sum2 = 0;
|
||||
for(const auto & v : vii)
|
||||
{
|
||||
sum1 += v.first;
|
||||
sum2 += v.second;
|
||||
}
|
||||
|
||||
|
||||
assert(sum1 == 4950);
|
||||
assert(sum2 == 328350l);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
#include "opp_part1.h"
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <opp/vector.h>
|
||||
|
||||
class A
|
||||
{
|
||||
protected:
|
||||
int a, b;
|
||||
|
||||
public:
|
||||
A(int a_, int b_)
|
||||
: a(a_), b(b_)
|
||||
{}
|
||||
|
||||
int sum(void) const
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
};
|
||||
|
||||
class AS
|
||||
{
|
||||
protected:
|
||||
opp::vector<A> va;
|
||||
public:
|
||||
AS(const opp::vector<A> & v)
|
||||
: va(v)
|
||||
{}
|
||||
|
||||
int sum(void)
|
||||
{
|
||||
int s = 0;
|
||||
for(const auto & a : va)
|
||||
s += a.sum();
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
#pragma compile("opp_part1.cpp")
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "opp_part2.h"
|
||||
|
||||
BS::BS(const opp::vector<A> & v)
|
||||
: va(v)
|
||||
{}
|
||||
|
||||
int BS::sum(void)
|
||||
{
|
||||
int s = 0;
|
||||
for(const auto & a : va)
|
||||
s += a.sum();
|
||||
return s;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "opp_part1.h"
|
||||
|
||||
class BS
|
||||
{
|
||||
protected:
|
||||
opp::vector<A> va;
|
||||
public:
|
||||
BS(const opp::vector<A> & v);
|
||||
int sum(void);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#pragma compile("opp_part2.cpp")
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "opp_part1.h"
|
||||
#include "opp_part2.h"
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
opp::vector<A> va;
|
||||
va.push_back(A(1, 2));
|
||||
va.push_back(A(3, 4));
|
||||
va.push_back(A(6, 4));
|
||||
va.push_back(A(0, 9));
|
||||
|
||||
AS as(va);
|
||||
|
||||
va.push_back(A(7, 1));
|
||||
|
||||
BS bs(va);
|
||||
|
||||
assert(bs.sum() == 2 + 12 + 24 + 7);
|
||||
assert(as.sum() == 2 + 12 + 24);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#include <opp/span.h>
|
||||
#include <opp/iostream.h>
|
||||
#include <opp/iterator.h>
|
||||
#include <opp/vector.h>
|
||||
#include <opp/array.h>
|
||||
#include <opp/numeric.h>
|
||||
#include <opp/algorithm.h>
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
static const int test[] = {7, 6, 5, 4, 3, 2, 1};
|
||||
|
||||
opp::span<const int, 7> st(test);
|
||||
opp::span<const int> sd(test, 7);
|
||||
|
||||
auto st1 = st.subspan<1>();
|
||||
auto sd1 = sd.subspan<1>();
|
||||
|
||||
auto st2 = st.subspan(2);
|
||||
auto sd2 = sd.subspan(2);
|
||||
|
||||
auto st3 = st.subspan<1, 4>();
|
||||
auto sd3 = sd.subspan<1, 4>();
|
||||
|
||||
auto st4 = st.subspan(2, 5);
|
||||
auto sd4 = sd.subspan(2, 5);
|
||||
|
||||
auto st5 = st.last(5);
|
||||
auto sd5 = sd.last(5);
|
||||
|
||||
assert(opp::accumulate(st.begin(), st.end(), 0) == 28);
|
||||
assert(opp::accumulate(sd.begin(), sd.end(), 0) == 28);
|
||||
|
||||
assert(opp::accumulate(st1.begin(), st1.end(), 0) == 21);
|
||||
assert(opp::accumulate(sd1.begin(), sd1.end(), 0) == 21);
|
||||
|
||||
assert(opp::accumulate(st2.begin(), st2.end(), 0) == 15);
|
||||
assert(opp::accumulate(sd2.begin(), sd2.end(), 0) == 15);
|
||||
|
||||
assert(opp::accumulate(st3.begin(), st3.end(), 0) == 18);
|
||||
assert(opp::accumulate(sd3.begin(), sd3.end(), 0) == 18);
|
||||
|
||||
assert(opp::accumulate(st4.begin(), st4.end(), 0) == 15);
|
||||
assert(opp::accumulate(sd4.begin(), sd4.end(), 0) == 15);
|
||||
|
||||
assert(opp::accumulate(st5.begin(), st5.end(), 0) == 15);
|
||||
assert(opp::accumulate(sd5.begin(), sd5.end(), 0) == 15);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
#include <opp/static_vector.h>
|
||||
#include <opp/algorithm.h>
|
||||
#include <assert.h>
|
||||
#include <opp/iostream.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
opp::static_vector<int, 20> a;
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
a.push_back(i);
|
||||
|
||||
int s = 0;
|
||||
for(int i=0; i<a.size(); i++)
|
||||
s += a[i];
|
||||
|
||||
assert(s == 45);
|
||||
|
||||
for(int i=0; i<5; i++)
|
||||
a.erase(i);
|
||||
|
||||
s = 0;
|
||||
for(int i=0; i<a.size(); i++)
|
||||
s += a[i];
|
||||
|
||||
assert(s == 1 + 3 + 5 + 7 + 9);
|
||||
|
||||
opp::static_vector<int, 100> v;
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
v.push_back(i);
|
||||
|
||||
assert(v.size() == 10);
|
||||
v.insert(0, 20);
|
||||
assert(v.size() == 11);
|
||||
v.insert(6, 21);
|
||||
assert(v.size() == 12);
|
||||
v.insert(12, 22);
|
||||
|
||||
int * fi = opp::find(v.begin(), v.end(), 21);
|
||||
|
||||
fi = v.insert(fi, 30);
|
||||
fi = v.insert(fi, 31);
|
||||
fi = v.insert(fi, 32);
|
||||
|
||||
assert(v.size() == 16);
|
||||
assert(v[0] == 20);
|
||||
assert(v[15] == 22);
|
||||
assert(v[8] == 32);
|
||||
|
||||
fi = opp::find(v.begin(), v.end(), 32);
|
||||
|
||||
for(int i=0; i<30; i++)
|
||||
{
|
||||
fi = v.insert(fi, i + 40);
|
||||
}
|
||||
|
||||
assert(v.size() == 46);
|
||||
assert(v[28] == 60);
|
||||
|
||||
v.erase(10, 10);
|
||||
|
||||
for(int i : v)
|
||||
opp::cout << i << ", ";
|
||||
opp::cout << "\n";
|
||||
|
||||
assert(v.size() == 36);
|
||||
assert(v[18] == 60);
|
||||
|
||||
v.assign(42, 11);
|
||||
|
||||
assert(v.size() == 42);
|
||||
assert(v[0] == 11);
|
||||
assert(v[15] == 11);
|
||||
assert(v[41] == 11);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
#include <opp/string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <opp/sstream.h>
|
||||
#include <math.h>
|
||||
|
||||
using opp::ostringstream;
|
||||
using opp::istringstream;
|
||||
using opp::endl;
|
||||
|
||||
float fdist(float a, float b)
|
||||
{
|
||||
float d = fabs(a - b);
|
||||
a = fabs(a);
|
||||
b = fabs(b);
|
||||
return d / (a > b ? a : b);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ostringstream os;
|
||||
|
||||
for(int i=0; i<40; i++)
|
||||
{
|
||||
os << i << endl;
|
||||
}
|
||||
|
||||
istringstream is(os.str());
|
||||
|
||||
int j = 0, k = 47;
|
||||
#if 1
|
||||
|
||||
while (is >> k)
|
||||
{
|
||||
assert(k == j++);
|
||||
}
|
||||
|
||||
assert(j == 40);
|
||||
#endif
|
||||
os.str(opp::string());
|
||||
|
||||
#if 0
|
||||
cout << "[" << os.str() << "]" << endl;
|
||||
os << "HELLO";
|
||||
cout << "[" << os.str() << "]" << endl;
|
||||
#endif
|
||||
#if 1
|
||||
|
||||
float f = 1.0, g = 1.0;
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
{
|
||||
os << f << " " << g << endl;
|
||||
// cout << os.str();
|
||||
|
||||
f *= 5.1;
|
||||
g *= 0.12;
|
||||
}
|
||||
|
||||
|
||||
is.str(os.str());
|
||||
|
||||
f = 1.0, g = 1.0;
|
||||
|
||||
float fr, gr;
|
||||
|
||||
j = 0;
|
||||
while (is >> fr >> gr)
|
||||
{
|
||||
// cout << f << " " << fr << ", " << g << " " << gr << ", " << fdist(fr, f) << endl;
|
||||
|
||||
assert(fdist(fr, f) < 1.0e-5);
|
||||
assert(fdist(gr, g) < 1.0e-5);
|
||||
|
||||
f *= 5.1;
|
||||
g *= 0.12;
|
||||
j++;
|
||||
}
|
||||
|
||||
assert(j == 10);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
#include <opp/string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
using opp::string;
|
||||
|
||||
static const char HelloWorld[] = "Hello World";
|
||||
static const char AndBeyond[] = "And Beyond";
|
||||
static const char And[] = "And";
|
||||
static const char HelloWorldAndBeyond[] = "Hello World And Beyond";
|
||||
|
||||
__noinline void test_create(void)
|
||||
{
|
||||
string s1();
|
||||
string s2(HelloWorld);
|
||||
string s3(s2);
|
||||
string s4('a');
|
||||
|
||||
assert(!strcmp(s2.tocstr(), HelloWorld));
|
||||
assert(!strcmp(s3.tocstr(), HelloWorld));
|
||||
assert(s4.size() == 1 && s4[0] == 'a');
|
||||
}
|
||||
|
||||
__noinline void test_concat(void)
|
||||
{
|
||||
string s1();
|
||||
string s2(HelloWorld);
|
||||
string s3(AndBeyond);
|
||||
|
||||
string s4 = s1 + s2;
|
||||
string s5 = s2 + " " + s3;
|
||||
string s6 = s2 + " " + AndBeyond;
|
||||
|
||||
assert(!strcmp(s4.tocstr(), HelloWorld));
|
||||
assert(!strcmp(s5.tocstr(), HelloWorldAndBeyond));
|
||||
assert(!strcmp(s6.tocstr(), HelloWorldAndBeyond));
|
||||
}
|
||||
|
||||
__noinline void test_find(void)
|
||||
{
|
||||
string s1(HelloWorldAndBeyond);
|
||||
string s2(And);
|
||||
|
||||
assert(s1.find(HelloWorld) == 0);
|
||||
assert(s1.find(AndBeyond) == 12);
|
||||
assert(s1.find(And) == 12);
|
||||
assert(s1.find(s2) == 12);
|
||||
|
||||
assert(s1.find(' ') == 5);
|
||||
assert(s1.find(' ', 6) == 11);
|
||||
}
|
||||
|
||||
__noinline void test_assign(void)
|
||||
{
|
||||
string s1(HelloWorld);
|
||||
string s2(AndBeyond);
|
||||
string s3;
|
||||
s3 = s1;
|
||||
s3 = s2;
|
||||
s3 = s1;
|
||||
s3 += " ";
|
||||
s3 += s2;
|
||||
|
||||
assert(!strcmp(s3.tocstr(), HelloWorldAndBeyond));
|
||||
|
||||
s3 <<= 12;
|
||||
|
||||
assert(!strcmp(s3.tocstr(), AndBeyond));
|
||||
|
||||
s3 = HelloWorldAndBeyond;
|
||||
|
||||
assert(!strcmp(s3.tocstr(), HelloWorldAndBeyond));
|
||||
|
||||
s3 >>= 11;
|
||||
|
||||
assert(!strcmp(s3.tocstr(), HelloWorld));
|
||||
}
|
||||
|
||||
static char * test;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test = new char;
|
||||
|
||||
unsigned avail = heapfree();
|
||||
|
||||
test_create();
|
||||
assert(avail == heapfree());
|
||||
|
||||
test_concat();
|
||||
assert(avail == heapfree());
|
||||
|
||||
test_find();
|
||||
assert(avail == heapfree());
|
||||
|
||||
test_assign();
|
||||
assert(avail == heapfree());
|
||||
|
||||
delete test;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
#include <opp/string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
using opp::string;
|
||||
|
||||
|
||||
const string s1;
|
||||
const string s2 = "Hello";
|
||||
const string s3{"World"};
|
||||
|
||||
const string a1[2];
|
||||
const string a2[2] = {"Hello", "World"};
|
||||
const string a3[2] = {opp::string("Hello"), opp::string("World")};
|
||||
|
||||
|
||||
const string d1[3][2];
|
||||
const string d2[3][2] = {{"Hello", "World"}, {"aaa", "bbb"}, {"ccc", "ddd"}};
|
||||
const string d3[3][2] =
|
||||
{{opp::string("Hello"), opp::string("World")},
|
||||
{opp::string("aaa"), opp::string("bbb")},
|
||||
{opp::string("ccc"), opp::string("ddd")}};
|
||||
|
||||
void test_global_init(void)
|
||||
{
|
||||
assert(!strcmp(s1.tocstr(), ""));
|
||||
assert(!strcmp(s2.tocstr(), "Hello"));
|
||||
assert(!strcmp(s3.tocstr(), "World"));
|
||||
}
|
||||
|
||||
|
||||
void test_global_ainit(void)
|
||||
{
|
||||
assert(!strcmp(a1[0].tocstr(), ""));
|
||||
assert(!strcmp(a1[1].tocstr(), ""));
|
||||
|
||||
assert(!strcmp(a2[0].tocstr(), "Hello"));
|
||||
assert(!strcmp(a2[1].tocstr(), "World"));
|
||||
|
||||
assert(!strcmp(a3[0].tocstr(), "Hello"));
|
||||
assert(!strcmp(a3[1].tocstr(), "World"));
|
||||
}
|
||||
|
||||
void test_global_dinit(void)
|
||||
{
|
||||
assert(!strcmp(d1[0][0].tocstr(), ""));
|
||||
assert(!strcmp(d1[2][1].tocstr(), ""));
|
||||
|
||||
assert(!strcmp(d2[0][0].tocstr(), "Hello"));
|
||||
assert(!strcmp(d2[2][1].tocstr(), "ddd"));
|
||||
|
||||
assert(!strcmp(d3[0][0].tocstr(), "Hello"));
|
||||
assert(!strcmp(d3[2][1].tocstr(), "ddd"));
|
||||
}
|
||||
|
||||
|
||||
void test_local_init(void)
|
||||
{
|
||||
const string s1;
|
||||
const string s2 = "Hello";
|
||||
const string s3{"World"};
|
||||
|
||||
assert(!strcmp(s1.tocstr(), ""));
|
||||
assert(!strcmp(s2.tocstr(), "Hello"));
|
||||
assert(!strcmp(s3.tocstr(), "World"));
|
||||
}
|
||||
|
||||
|
||||
void test_local_ainit(void)
|
||||
{
|
||||
const string a1[2];
|
||||
const string a2[2] = {"Hello", "World"};
|
||||
const string a3[2] = {opp::string("Hello"), opp::string("World")};
|
||||
|
||||
assert(!strcmp(a1[0].tocstr(), ""));
|
||||
assert(!strcmp(a1[1].tocstr(), ""));
|
||||
|
||||
assert(!strcmp(a2[0].tocstr(), "Hello"));
|
||||
assert(!strcmp(a2[1].tocstr(), "World"));
|
||||
|
||||
assert(!strcmp(a3[0].tocstr(), "Hello"));
|
||||
assert(!strcmp(a3[1].tocstr(), "World"));
|
||||
}
|
||||
|
||||
void test_local_dinit(void)
|
||||
{
|
||||
const string d1[3][2];
|
||||
const string d2[3][2] = {{"Hello", "World"}, {"aaa", "bbb"}, {"ccc", "ddd"}};
|
||||
const string d3[3][2] =
|
||||
{{opp::string("Hello"), opp::string("World")},
|
||||
{opp::string("aaa"), opp::string("bbb")},
|
||||
{opp::string("ccc"), opp::string("ddd")}};
|
||||
|
||||
assert(!strcmp(d1[0][0].tocstr(), ""));
|
||||
assert(!strcmp(d1[2][1].tocstr(), ""));
|
||||
|
||||
assert(!strcmp(d2[0][0].tocstr(), "Hello"));
|
||||
assert(!strcmp(d2[2][1].tocstr(), "ddd"));
|
||||
|
||||
assert(!strcmp(d3[0][0].tocstr(), "Hello"));
|
||||
assert(!strcmp(d3[2][1].tocstr(), "ddd"));
|
||||
}
|
||||
|
||||
class X
|
||||
{
|
||||
public:
|
||||
const string s1;
|
||||
const string s2 = "Hello";
|
||||
const string s3;
|
||||
|
||||
const string a1[2];
|
||||
const string a2[2] = {"Hello", "World"};
|
||||
|
||||
const string d1[3][2];
|
||||
const string d2[3][2] = {{"Hello", "World"}, {"aaa", "bbb"}, {"ccc", "ddd"}};
|
||||
|
||||
X() : s3("World") {}
|
||||
};
|
||||
|
||||
void test_member_init(void)
|
||||
{
|
||||
X x;
|
||||
|
||||
assert(!strcmp(x.s1.tocstr(), ""));
|
||||
assert(!strcmp(x.s2.tocstr(), "Hello"));
|
||||
assert(!strcmp(x.s3.tocstr(), "World"));
|
||||
}
|
||||
|
||||
void test_member_ainit(void)
|
||||
{
|
||||
X x;
|
||||
|
||||
assert(!strcmp(x.a1[0].tocstr(), ""));
|
||||
assert(!strcmp(x.a1[1].tocstr(), ""));
|
||||
|
||||
assert(!strcmp(x.a2[0].tocstr(), "Hello"));
|
||||
assert(!strcmp(x.a2[1].tocstr(), "World"));
|
||||
}
|
||||
|
||||
void test_member_dinit(void)
|
||||
{
|
||||
X x;
|
||||
|
||||
assert(!strcmp(x.d1[0][0].tocstr(), ""));
|
||||
assert(!strcmp(x.d1[2][1].tocstr(), ""));
|
||||
|
||||
assert(!strcmp(x.d2[0][0].tocstr(), "Hello"));
|
||||
assert(!strcmp(x.d2[2][1].tocstr(), "ddd"));
|
||||
}
|
||||
|
||||
void test_copy_init(void)
|
||||
{
|
||||
X x;
|
||||
X y(x);
|
||||
|
||||
assert(!strcmp(y.s1.tocstr(), ""));
|
||||
assert(!strcmp(y.s2.tocstr(), "Hello"));
|
||||
assert(!strcmp(y.s3.tocstr(), "World"));
|
||||
}
|
||||
|
||||
void test_copy_ainit(void)
|
||||
{
|
||||
X x;
|
||||
X y(x);
|
||||
|
||||
assert(!strcmp(y.a1[0].tocstr(), ""));
|
||||
assert(!strcmp(y.a1[1].tocstr(), ""));
|
||||
|
||||
assert(!strcmp(y.a2[0].tocstr(), "Hello"));
|
||||
assert(!strcmp(y.a2[1].tocstr(), "World"));
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_global_init();
|
||||
test_global_ainit();
|
||||
test_global_dinit();
|
||||
|
||||
for(int i=0; i<10000; i++)
|
||||
{
|
||||
test_local_init();
|
||||
test_local_ainit();
|
||||
}
|
||||
|
||||
test_member_init();
|
||||
test_member_ainit();
|
||||
|
||||
test_copy_init();
|
||||
test_copy_ainit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
#include <opp/vector.h>
|
||||
#include <opp/algorithm.h>
|
||||
#include <assert.h>
|
||||
#include <opp/iostream.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
opp::vector<int> a;
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
a.push_back(i);
|
||||
|
||||
int s = 0;
|
||||
for(int i=0; i<a.size(); i++)
|
||||
s += a[i];
|
||||
|
||||
assert(s == 45);
|
||||
|
||||
for(int i=0; i<5; i++)
|
||||
a.erase(i);
|
||||
|
||||
s = 0;
|
||||
for(int i=0; i<a.size(); i++)
|
||||
s += a[i];
|
||||
|
||||
assert(s == 1 + 3 + 5 + 7 + 9);
|
||||
|
||||
opp::vector<int> v;
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
v.push_back(i);
|
||||
|
||||
assert(v.size() == 10);
|
||||
v.insert(0, 20);
|
||||
assert(v.size() == 11);
|
||||
v.insert(6, 21);
|
||||
assert(v.size() == 12);
|
||||
v.insert(12, 22);
|
||||
|
||||
int * fi = opp::find(v.begin(), v.end(), 21);
|
||||
|
||||
fi = v.insert(fi, 30);
|
||||
fi = v.insert(fi, 31);
|
||||
fi = v.insert(fi, 32);
|
||||
|
||||
assert(v.size() == 16);
|
||||
assert(v[0] == 20);
|
||||
assert(v[15] == 22);
|
||||
assert(v[8] == 32);
|
||||
|
||||
fi = opp::find(v.begin(), v.end(), 32);
|
||||
|
||||
for(int i=0; i<30; i++)
|
||||
{
|
||||
fi = v.insert(fi, i + 40);
|
||||
}
|
||||
|
||||
assert(v.size() == 46);
|
||||
assert(v[28] == 60);
|
||||
|
||||
v.erase(10, 10);
|
||||
|
||||
for(int i : v)
|
||||
opp::cout << i << ", ";
|
||||
opp::cout << "\n";
|
||||
|
||||
assert(v.size() == 36);
|
||||
assert(v[18] == 60);
|
||||
|
||||
v.assign(42, 11);
|
||||
|
||||
assert(v.size() == 42);
|
||||
assert(v[0] == 11);
|
||||
assert(v[15] == 11);
|
||||
assert(v[41] == 11);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <opp/vector.h>
|
||||
#include <opp/string.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <opp/iostream.h>
|
||||
|
||||
using opp::string;
|
||||
using opp::vector;
|
||||
|
||||
string join(const vector<string> & vs)
|
||||
{
|
||||
string sj;
|
||||
for(int i=0; i<vs.size(); i++)
|
||||
sj += vs[i];
|
||||
return sj;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
vector<string> vs;
|
||||
string a;
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
{
|
||||
vs.push_back(a);
|
||||
a += "x";
|
||||
}
|
||||
|
||||
int s = 0;
|
||||
for(int i=0; i<10; i++)
|
||||
s += vs[i].size();
|
||||
|
||||
assert(s == 45);
|
||||
|
||||
assert(join(vs).size() == 45);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
int option(bool a, int b, int c)
|
||||
{
|
||||
return a ? b : c;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
assert(option(true, 1, 2) == 1);
|
||||
assert(option(false, 1, 2) == 2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
static const char sintab[] = {
|
||||
128, 131, 134, 137, 140, 144, 147, 150, 153, 156, 159, 162, 165, 168, 171, 174, 177, 179, 182, 185, 188, 191, 193, 196, 199, 201, 204, 206, 209, 211, 213, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 235, 237, 239, 240, 241, 243, 244, 245, 246, 248, 249, 250, 250, 251, 252, 253, 253, 254, 254, 254, 255, 255, 255,
|
||||
255, 255, 255, 255, 254, 254, 254, 253, 253, 252, 251, 250, 250, 249, 248, 246, 245, 244, 243, 241, 240, 239, 237, 235, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 213, 211, 209, 206, 204, 201, 199, 196, 193, 191, 188, 185, 182, 179, 177, 174, 171, 168, 165, 162, 159, 156, 153, 150, 147, 144, 140, 137, 134, 131,
|
||||
128, 125, 122, 119, 116, 112, 109, 106, 103, 100, 97, 94, 91, 88, 85, 82, 79, 77, 74, 71, 68, 65, 63, 60, 57, 55, 52, 50, 47, 45, 43, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 21, 19, 17, 16, 15, 13, 12, 11, 10, 8, 7, 6, 6, 5, 4, 3, 3, 2, 2, 2, 1, 1, 1,
|
||||
1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 6, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 19, 21, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 43, 45, 47, 50, 52, 55, 57, 60, 63, 65, 68, 71, 74, 77, 79, 82, 85, 88, 91, 94, 97, 100, 103, 106, 109, 112, 116, 119, 122, 125
|
||||
};
|
||||
|
||||
char Screen0[1024], Screen1[1024];
|
||||
|
||||
char colormap0[256], colormap1[256];
|
||||
|
||||
|
||||
char colors0[] = {0, 6, 14, 1, 13, 5, 0};
|
||||
char colors1[] = {0, 9, 7, 1, 15, 12, 0};
|
||||
|
||||
unsigned c1A, c1B, c2A, c2B, c3A, c3B;
|
||||
int d1A, d1B, d2A, d2B, d3A, d3B;
|
||||
|
||||
void inithires(void)
|
||||
{
|
||||
for(int i=0; i<256; i++)
|
||||
{
|
||||
colormap0[i] = colors0[i / 37];
|
||||
colormap1[i] = colors1[i / 37] << 4;
|
||||
}
|
||||
}
|
||||
|
||||
inline void doplasma(char * scrn)
|
||||
{
|
||||
char xbuf0[40], xbuf1[40];
|
||||
char ybuf0[25], ybuf1[25];
|
||||
|
||||
char c2a = c2A >> 8;
|
||||
char c2b = c2B >> 8;
|
||||
char c1a = c1A >> 8;
|
||||
char c1b = c1B >> 8;
|
||||
|
||||
for (char i = 0; i < 25; i++) {
|
||||
ybuf0[i] = sintab[(c1a + c2a) & 0xff] + sintab[c1b];
|
||||
c1a += 13;
|
||||
c1b -= 5;
|
||||
}
|
||||
|
||||
for (char i = 0; i < 40; i++) {
|
||||
xbuf0[i] = sintab[(c2a + c1b) & 0xff] + sintab[c2b];
|
||||
c2a += 11;
|
||||
c2b -= 7;
|
||||
}
|
||||
|
||||
c2a = c2B >> 8;
|
||||
c2b = c3A >> 8;
|
||||
c1a = c1B >> 8;
|
||||
c1b = c3B >> 8;
|
||||
|
||||
for (char i = 0; i < 25; i++) {
|
||||
ybuf1[i] = sintab[(c1b + c2a) & 0xff] + sintab[c1a];
|
||||
c1a += 4;
|
||||
c1b -= 6;
|
||||
}
|
||||
|
||||
for (char i = 0; i < 40; i++) {
|
||||
xbuf1[i] = sintab[(c2b + c1a) & 0xff] + sintab[c2a];
|
||||
c2a += 7;
|
||||
c2b -= 9;
|
||||
}
|
||||
|
||||
#pragma unroll(full)
|
||||
for (char k=0; k<5; k++)
|
||||
{
|
||||
char tbuf0[5], tbuf1[5];
|
||||
#pragma unroll(full)
|
||||
for (char i = 0; i < 4; i++)
|
||||
{
|
||||
tbuf0[i] = ybuf0[5 * k + i + 1] - ybuf0[5 * k + i];
|
||||
tbuf1[i] = ybuf1[5 * k + i + 1] - ybuf1[5 * k + i];
|
||||
}
|
||||
|
||||
for (signed char i = 39; i >= 0; i--)
|
||||
{
|
||||
char t = xbuf0[i] + ybuf0[5 * k];
|
||||
char u = xbuf1[i] + ybuf1[5 * k];
|
||||
|
||||
#pragma unroll(full)
|
||||
for (char j = 0; j < 5; j++)
|
||||
{
|
||||
scrn[40 * j + 200 * k + i] = colormap0[u] | colormap1[u];
|
||||
t += tbuf0[j];
|
||||
u += tbuf1[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c1A += 8 * ((int)sintab[d1A] - 128);
|
||||
c1B += 16 * ((int)sintab[d1B] - 128);
|
||||
c2A += 8 * ((int)sintab[d2A] - 128);
|
||||
c2B += 16 * ((int)sintab[d2B] - 128);
|
||||
c3A += 6 * ((int)sintab[d3A] - 128);
|
||||
c3B += 12 * ((int)sintab[d3B] - 128);
|
||||
|
||||
d1A += 3;
|
||||
d1B += rand() & 3;
|
||||
d2A += 5;
|
||||
d2B += rand() & 3;
|
||||
d3A += 2;
|
||||
d3B += rand() & 3;
|
||||
}
|
||||
|
||||
void doplasma0(void)
|
||||
{
|
||||
doplasma(Screen0);
|
||||
}
|
||||
|
||||
void doplasma1(void)
|
||||
{
|
||||
doplasma(Screen1);
|
||||
}
|
||||
|
||||
unsigned checksum(const char * scr)
|
||||
{
|
||||
unsigned s = 0x1234;
|
||||
for(int i=0; i<1024; i++)
|
||||
{
|
||||
unsigned m = s & 1;
|
||||
s >>= 1;
|
||||
if (m)
|
||||
s ^= 0x2152;
|
||||
s ^= scr[i];
|
||||
}
|
||||
return s;
|
||||
}
|
||||
int main(void)
|
||||
{
|
||||
inithires();
|
||||
|
||||
doplasma0();
|
||||
doplasma1();
|
||||
doplasma0();
|
||||
doplasma1();
|
||||
doplasma0();
|
||||
doplasma1();
|
||||
|
||||
return checksum(Screen0) + checksum(Screen1) - 16337;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#include <assert.h>
|
||||
|
||||
struct X
|
||||
{
|
||||
int a;
|
||||
};
|
||||
|
||||
X x[5] = {
|
||||
{1}, {2}, {3}, {4}, {5}
|
||||
};
|
||||
|
||||
X * y;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
y = x;
|
||||
assert(y == x);
|
||||
y = x + 1;
|
||||
assert(y == x + 1);
|
||||
y = &(x[2]);
|
||||
assert(y == x + 2);
|
||||
y = x + 3;
|
||||
assert(y == &(x[3]));
|
||||
y = x ;
|
||||
assert(y == (struct X*)x);
|
||||
|
||||
y = x;
|
||||
assert(x == y);
|
||||
y = x + 1;
|
||||
assert(x + 1 == y);
|
||||
y = &(x[2]);
|
||||
assert(x + 2 == y);
|
||||
y = x + 3;
|
||||
assert(&(x[3]) == y);
|
||||
y = x ;
|
||||
assert((struct X*)x == y);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#if 1
|
||||
|
||||
const struct A {
|
||||
char w;
|
||||
int b[5];
|
||||
struct {
|
||||
int c[5];
|
||||
} o;
|
||||
} a = {22,
|
||||
{4, 5, 6, 7, 8},
|
||||
{
|
||||
{4, 5, 6, 7, 8}
|
||||
}
|
||||
};
|
||||
|
||||
const int * t[4] = {
|
||||
a.b + 1 + 1
|
||||
};
|
||||
|
||||
const int * v[4] = {
|
||||
a.o.c + 1 + 1
|
||||
};
|
||||
|
||||
int q[5] = {4, 5, 6, 7, 8};
|
||||
|
||||
const int * u[4] = {
|
||||
q + 2
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return
|
||||
u[0][0] + (q + 2)[2] - 6 - 8 +
|
||||
v[0][0] + (a.o.c + 2)[2] - 6 - 8 +
|
||||
t[0][0] + (a.b + 2)[2] - 6 - 8;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
struct Node
|
||||
{
|
||||
int a;
|
||||
char s[10];
|
||||
};
|
||||
|
||||
void qsort(Node * n, int s)
|
||||
{
|
||||
if (s > 1)
|
||||
{
|
||||
Node pn = n[0];
|
||||
int pi = 0;
|
||||
for(int i=1; i<s; i++)
|
||||
{
|
||||
if (strcmp(n[i].s, pn.s) < 0)
|
||||
{
|
||||
n[pi] = n[i];
|
||||
pi++;
|
||||
n[i] = n[pi];
|
||||
}
|
||||
}
|
||||
n[pi] = pn;
|
||||
|
||||
qsort(n, pi);
|
||||
qsort(n + pi + 1, s - pi - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void shuffle(Node * n, int s)
|
||||
{
|
||||
for(int i=0; i<s; i++)
|
||||
{
|
||||
int t = rand() % s;
|
||||
Node nt = n[i]; n[i] = n[t]; n[t] = nt;
|
||||
}
|
||||
}
|
||||
|
||||
void init(Node * n, int s)
|
||||
{
|
||||
for(int i=0; i<s; i++)
|
||||
{
|
||||
n[i].a = i;
|
||||
sprintf(n[i].s, "%.5d", i);
|
||||
}
|
||||
}
|
||||
|
||||
static const int size = 1000;
|
||||
|
||||
Node field[size];
|
||||
|
||||
void show(Node * n, int s)
|
||||
{
|
||||
for(int i=0; i<s; i++)
|
||||
{
|
||||
printf("%3d : %3d, %s\n", i, n[i].a, n[i].s);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void check(Node * n, int s)
|
||||
{
|
||||
for(int i=0; i<s; i++)
|
||||
{
|
||||
assert(n[i].a == i);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
init(field, size);
|
||||
// show(field, size);
|
||||
shuffle(field, size);
|
||||
// show(field, size);
|
||||
qsort(field, size);
|
||||
// show(field, size);
|
||||
check(field, size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// randsumtest
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
long lsum = 0;
|
||||
for(unsigned i=0; i<1000; i++)
|
||||
lsum += rand();
|
||||
|
||||
assert(lsum == 32157742L);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int fib(int a)
|
||||
{
|
||||
if (a < 2)
|
||||
return a;
|
||||
else
|
||||
return fib(a - 1) + fib(a - 2);
|
||||
}
|
||||
|
||||
struct Node
|
||||
{
|
||||
char value;
|
||||
Node * left, * right;
|
||||
};
|
||||
|
||||
typedef Node * NodePtr;
|
||||
|
||||
|
||||
NodePtr newnode(void)
|
||||
{
|
||||
return (NodePtr)malloc(sizeof(Node));
|
||||
}
|
||||
|
||||
Node * insert(Node * tree, char v)
|
||||
{
|
||||
if (tree)
|
||||
{
|
||||
if (v < tree->value)
|
||||
{
|
||||
tree->left = insert(tree->left, v);
|
||||
}
|
||||
else
|
||||
{
|
||||
tree->right = insert(tree->right, v);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tree = newnode();
|
||||
tree->value = v;
|
||||
tree->left = nullptr;
|
||||
tree->right = nullptr;
|
||||
}
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
char * collect(Node * tree, char * p)
|
||||
{
|
||||
if (tree)
|
||||
{
|
||||
p = collect(tree->left, p);
|
||||
*p++= tree->value;
|
||||
p = collect(tree->right, p);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void btest(void)
|
||||
{
|
||||
const char * str = "HELLO WORLD";
|
||||
char buff[20];
|
||||
|
||||
int i = 0;
|
||||
Node * tree = nullptr;
|
||||
|
||||
while (str[i])
|
||||
{
|
||||
tree = insert(tree, str[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
collect(tree, buff)[0] = 0;
|
||||
|
||||
assert(strcmp(buff, " DEHLLLOORW") == 0);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
assert(fib(23) == 28657);
|
||||
|
||||
btest();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
#include <assert.h>
|
||||
|
||||
__noinline unsigned long rollright32(unsigned long a) {
|
||||
unsigned long tmp = a & 1;
|
||||
return ( a >> 1) + (tmp << 31);
|
||||
}
|
||||
|
||||
__noinline unsigned rollright16(unsigned a) {
|
||||
unsigned tmp = a & 1;
|
||||
return ( a >> 1) + (tmp << 15);
|
||||
}
|
||||
|
||||
__noinline char rollright8(char a) {
|
||||
char tmp = a & 1;
|
||||
return ( a >> 1) + (tmp << 7);
|
||||
}
|
||||
|
||||
__noinline unsigned long rollleft32(unsigned long a) {
|
||||
unsigned long tmp = (a >> 31) & 1;
|
||||
return ( a << 1) + tmp;
|
||||
}
|
||||
|
||||
__noinline unsigned rollleft16(unsigned a) {
|
||||
unsigned tmp = (a >> 15) & 1;
|
||||
return ( a << 1) + tmp;
|
||||
}
|
||||
|
||||
__noinline char rollleft8(char a) {
|
||||
char tmp = (a >> 7) & 1;
|
||||
return ( a << 1) + tmp;
|
||||
}
|
||||
|
||||
int main() {
|
||||
unsigned long lv = 0x12345678ul;
|
||||
unsigned val = 0x1234;
|
||||
char c=0x12;
|
||||
|
||||
unsigned long lvt[33];
|
||||
unsigned valt[17];
|
||||
char ct[9];
|
||||
|
||||
lvt[0] = lv;
|
||||
valt[0] = val;
|
||||
ct[0] = c;
|
||||
|
||||
assert(rollleft8(rollright8(c)) == c);
|
||||
assert(rollleft16(rollright16(val)) == val);
|
||||
assert(rollleft32(rollright32(lv)) == lv);
|
||||
|
||||
for(int i=0; i<32; i++)
|
||||
lvt[i + 1] = rollright32(lvt[i]);
|
||||
for(int i=0; i<16; i++)
|
||||
valt[i + 1] = rollright16(valt[i]);
|
||||
for(int i=0; i<8; i++)
|
||||
ct[i + 1] = rollright8(ct[i]);
|
||||
|
||||
for(int i=0; i<=32; i++)
|
||||
{
|
||||
assert(lvt[32 - i] == lv);
|
||||
lv = rollleft32(lv);
|
||||
}
|
||||
|
||||
for(int i=0; i<=16; i++)
|
||||
{
|
||||
assert(valt[16 - i] == val);
|
||||
val = rollleft16(val);
|
||||
}
|
||||
|
||||
for(int i=0; i<=8; i++)
|
||||
{
|
||||
assert(ct[8 - i] == c);
|
||||
c = rollleft8(c);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
#include <assert.h>
|
||||
|
||||
#define Screen ((char *)0x0400)
|
||||
|
||||
void scroll_left(void)
|
||||
{
|
||||
char * dp = Screen;
|
||||
for(char y=0; y<25; y++)
|
||||
{
|
||||
for(char x=0; x<39; x++)
|
||||
{
|
||||
dp[x] = dp[x + 1];
|
||||
}
|
||||
dp += 40;
|
||||
}
|
||||
}
|
||||
|
||||
void scroll_right(void)
|
||||
{
|
||||
char * dp = Screen;
|
||||
for(char y=0; y<25; y++)
|
||||
{
|
||||
for(char x=39; x>0; x--)
|
||||
{
|
||||
dp[x] = dp[x - 1];
|
||||
}
|
||||
dp += 40;
|
||||
}
|
||||
}
|
||||
|
||||
void scroll_up(void)
|
||||
{
|
||||
char * dp = Screen, * sp = dp + 40;
|
||||
for(char y=0; y<24; y++)
|
||||
{
|
||||
for(char x=0; x<40; x++)
|
||||
{
|
||||
dp[x] = sp[x];
|
||||
}
|
||||
dp = sp;
|
||||
sp += 40;
|
||||
}
|
||||
}
|
||||
|
||||
void scroll_down(void)
|
||||
{
|
||||
char * dp = Screen + 24 * 40, * sp = dp - 40;
|
||||
for(char y=0; y<24; y++)
|
||||
{
|
||||
for(char x=0; x<40; x++)
|
||||
{
|
||||
dp[x] = sp[x];
|
||||
}
|
||||
dp = sp;
|
||||
sp -= 40;
|
||||
}
|
||||
}
|
||||
|
||||
void fill_screen(void)
|
||||
{
|
||||
for(char y=0; y<25; y++)
|
||||
{
|
||||
for(char x=0; x<40; x++)
|
||||
{
|
||||
Screen[40 * y + x] = 7 * y + x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void check_screen(int dy, int dx)
|
||||
{
|
||||
for(int y=0; y<25; y++)
|
||||
{
|
||||
for(int x=0; x<40; x++)
|
||||
{
|
||||
int sy = y + dy;
|
||||
int sx = x + dx;
|
||||
|
||||
char c = 7 * y + x;
|
||||
if (sy >= 0 && sy < 25 && sx >= 0 && sx < 40)
|
||||
c = 7 * sy + sx;
|
||||
|
||||
assert(Screen[40 * y + x] == c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fill_screen();
|
||||
scroll_left();
|
||||
check_screen(0, 1);
|
||||
|
||||
fill_screen();
|
||||
scroll_right();
|
||||
check_screen(0, -1);
|
||||
|
||||
fill_screen();
|
||||
scroll_up();
|
||||
check_screen(1, 0);
|
||||
|
||||
fill_screen();
|
||||
scroll_down();
|
||||
check_screen(-1, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <assert.h>
|
||||
|
||||
__noinline int base_add(int add, int shl, char a)
|
||||
{
|
||||
return (a << shl) + add;
|
||||
}
|
||||
|
||||
template<int add, int shl>
|
||||
void test_add(char a)
|
||||
{
|
||||
assert((a << shl) + add == base_add(add, shl, a));
|
||||
}
|
||||
|
||||
template<int add>
|
||||
void test_adds(char a)
|
||||
{
|
||||
#for(i, 16) test_add<add, i>(a);
|
||||
}
|
||||
|
||||
__noinline int base_sub(int sub, int shl, char a)
|
||||
{
|
||||
return (a << shl) - sub;
|
||||
}
|
||||
|
||||
template<int sub, int shl>
|
||||
void test_sub(char a)
|
||||
{
|
||||
assert(int(a << shl) - sub == base_sub(sub, shl, a));
|
||||
}
|
||||
|
||||
template<int sub>
|
||||
void test_subs(char a)
|
||||
{
|
||||
#for(i, 16) test_sub<sub, i>(a);
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for(int i=0; i<256; i++)
|
||||
test_adds<15>(i);
|
||||
for(int i=0; i<256; i++)
|
||||
test_adds<16>(i);
|
||||
for(int i=0; i<256; i++)
|
||||
test_adds<111>(i);
|
||||
for(int i=0; i<256; i++)
|
||||
test_adds<4096>(i);
|
||||
for(int i=0; i<256; i++)
|
||||
test_adds<13421>(i);
|
||||
for(int i=0; i<256; i++)
|
||||
test_subs<15>(i);
|
||||
for(int i=0; i<256; i++)
|
||||
test_subs<16>(i);
|
||||
for(int i=0; i<256; i++)
|
||||
test_subs<4096>(i);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,335 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
void testi(const char * fmt, int val, const char * tst)
|
||||
{
|
||||
char buffer[32];
|
||||
|
||||
sprintf(buffer, fmt, val);
|
||||
printf("%s:%s\n", buffer, tst);
|
||||
assert(!strcmp(buffer, tst));
|
||||
}
|
||||
|
||||
void testu(const char * fmt, unsigned val, const char * tst)
|
||||
{
|
||||
char buffer[32];
|
||||
|
||||
sprintf(buffer, fmt, val);
|
||||
printf("%s:%s\n", buffer, tst);
|
||||
assert(!strcmp(buffer, tst));
|
||||
}
|
||||
|
||||
void testil(const char * fmt, long val, const char * tst)
|
||||
{
|
||||
char buffer[32];
|
||||
|
||||
sprintf(buffer, fmt, val);
|
||||
printf("%s:%s\n", buffer, tst);
|
||||
assert(!strcmp(buffer, tst));
|
||||
}
|
||||
|
||||
void testul(const char * fmt, unsigned long val, const char * tst)
|
||||
{
|
||||
char buffer[32];
|
||||
|
||||
sprintf(buffer, fmt, val);
|
||||
printf("%s:%s\n", buffer, tst);
|
||||
assert(!strcmp(buffer, tst));
|
||||
}
|
||||
|
||||
void testf(const char * fmt, float val, const char * tst)
|
||||
{
|
||||
char buffer[32];
|
||||
|
||||
sprintf(buffer, fmt, val);
|
||||
printf("%s:%s\n", buffer, tst);
|
||||
assert(!strcmp(buffer, tst));
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
testi("%d", 0, "0");
|
||||
testi("%d", 1, "1");
|
||||
testi("%d", -1, "-1");
|
||||
testi("%d", 12, "12");
|
||||
testi("%d", 123, "123");
|
||||
testi("%d", 1234, "1234");
|
||||
testi("%d", 12345, "12345");
|
||||
testi("%d", -12345, "-12345");
|
||||
testi("%d", 32767, "32767");
|
||||
testi("%d", -32768, "-32768");
|
||||
|
||||
testi("%3d", 0, " 0");
|
||||
testi("%3d", 1, " 1");
|
||||
testi("%3d", -1, " -1");
|
||||
testi("%3d", 12, " 12");
|
||||
testi("%3d", 123, "123");
|
||||
testi("%3d", 1234, "1234");
|
||||
testi("%3d", 12345, "12345");
|
||||
testi("%3d", -12345, "-12345");
|
||||
testi("%3d", 32767, "32767");
|
||||
testi("%3d", -32768, "-32768");
|
||||
|
||||
testi("%03d", 0, "000");
|
||||
testi("%03d", 1, "001");
|
||||
// testi("%03d", -1, "-01");
|
||||
testi("%03d", 12, "012");
|
||||
testi("%03d", 123, "123");
|
||||
testi("%03d", 1234, "1234");
|
||||
testi("%03d", 12345, "12345");
|
||||
testi("%03d", -12345, "-12345");
|
||||
testi("%03d", 32767, "32767");
|
||||
testi("%03d", -32768, "-32768");
|
||||
|
||||
testi("%-4d", 0, "0 ");
|
||||
testi("%-4d", 1, "1 ");
|
||||
testi("%-4d", -1, "-1 ");
|
||||
testi("%-4d", 12, "12 ");
|
||||
testi("%-4d", 123, "123 ");
|
||||
testi("%-4d", 1234, "1234");
|
||||
testi("%-4d", 12345, "12345");
|
||||
testi("%-4d", -12345, "-12345");
|
||||
testi("%-4d", 32767, "32767");
|
||||
testi("%-4d", -32768, "-32768");
|
||||
|
||||
testi("%+d", 0, "+0");
|
||||
testi("%+d", 1, "+1");
|
||||
testi("%+d", -1, "-1");
|
||||
testi("%+d", 12, "+12");
|
||||
testi("%+d", 123, "+123");
|
||||
testi("%+d", 1234, "+1234");
|
||||
testi("%+d", 12345, "+12345");
|
||||
testi("%+d", -12345, "-12345");
|
||||
testi("%+d", 32767, "+32767");
|
||||
testi("%+d", -32768, "-32768");
|
||||
|
||||
|
||||
|
||||
testil("%ld", 0l, "0");
|
||||
testil("%ld", 1l, "1");
|
||||
testil("%ld", -1l, "-1");
|
||||
testil("%ld", 12l, "12");
|
||||
testil("%ld", 123l, "123");
|
||||
testil("%ld", 1234l, "1234");
|
||||
testil("%ld", 12345l, "12345");
|
||||
testil("%ld", -12345l, "-12345");
|
||||
testil("%ld", 32767l, "32767");
|
||||
testil("%ld", -32768l, "-32768");
|
||||
testil("%ld", 2147483647l, "2147483647");
|
||||
testil("%ld", -2147483648l, "-2147483648");
|
||||
|
||||
testil("%3ld", 0l, " 0");
|
||||
testil("%3ld", 1l, " 1");
|
||||
testil("%3ld", -1l, " -1");
|
||||
testil("%3ld", 12l, " 12");
|
||||
testil("%3ld", 123l, "123");
|
||||
testil("%3ld", 1234l, "1234");
|
||||
testil("%3ld", 12345l, "12345");
|
||||
testil("%3ld", -12345l, "-12345");
|
||||
testil("%3ld", 32767l, "32767");
|
||||
testil("%3ld", -32768l, "-32768");
|
||||
testil("%3ld", 2147483647l, "2147483647");
|
||||
testil("%3ld", -2147483648l, "-2147483648");
|
||||
|
||||
testil("%03ld", 0l, "000");
|
||||
testil("%03ld", 1l, "001");
|
||||
// testil("%03ld", -1l, "-01");
|
||||
testil("%03ld", 12l, "012");
|
||||
testil("%03ld", 123l, "123");
|
||||
testil("%03ld", 1234l, "1234");
|
||||
testil("%03ld", 12345l, "12345");
|
||||
testil("%03ld", -12345l, "-12345");
|
||||
testil("%03ld", 32767l, "32767");
|
||||
testil("%03ld", -32768l, "-32768");
|
||||
testil("%03ld", 2147483647l, "2147483647");
|
||||
testil("%03ld", -2147483648l, "-2147483648");
|
||||
|
||||
testil("%-4ld", 0l, "0 ");
|
||||
testil("%-4ld", 1l, "1 ");
|
||||
testil("%-4ld", -1l, "-1 ");
|
||||
testil("%-4ld", 12l, "12 ");
|
||||
testil("%-4ld", 123l, "123 ");
|
||||
testil("%-4ld", 1234l, "1234");
|
||||
testil("%-4ld", 12345l, "12345");
|
||||
testil("%-4ld", -12345l, "-12345");
|
||||
testil("%-4ld", 32767l, "32767");
|
||||
testil("%-4ld", -32768l, "-32768");
|
||||
testil("%-4ld", 2147483647l, "2147483647");
|
||||
testil("%-4ld", -2147483648l, "-2147483648");
|
||||
|
||||
testil("%+ld", 0l, "+0");
|
||||
testil("%+ld", 1l, "+1");
|
||||
testil("%+ld", -1l, "-1");
|
||||
testil("%+ld", 12l, "+12");
|
||||
testil("%+ld", 123l, "+123");
|
||||
testil("%+ld", 1234l, "+1234");
|
||||
testil("%+ld", 12345l, "+12345");
|
||||
testil("%+ld", -12345l, "-12345");
|
||||
testil("%+ld", 32767l, "+32767");
|
||||
testil("%+ld", -32768l, "-32768");
|
||||
testil("%+ld", 2147483647l, "+2147483647");
|
||||
testil("%+ld", -2147483648l, "-2147483648");
|
||||
|
||||
testu("%u", 0, "0");
|
||||
testu("%u", 1, "1");
|
||||
testu("%u", 12, "12");
|
||||
testu("%u", 123, "123");
|
||||
testu("%u", 1234, "1234");
|
||||
testu("%u", 12345, "12345");
|
||||
testu("%u", 32767, "32767");
|
||||
testu("%u", 32768, "32768");
|
||||
testu("%u", 65535, "65535");
|
||||
testu("%x", 0, "0");
|
||||
testu("%x", 0x49bf, "49bf");
|
||||
testu("%x", 0xffff, "ffff");
|
||||
testu("%X", 0x49bf, "49BF");
|
||||
testu("%X", 0xffff, "FFFF");
|
||||
|
||||
testu("%3u", 0, " 0");
|
||||
testu("%3u", 1, " 1");
|
||||
testu("%3u", 12, " 12");
|
||||
testu("%3u", 123, "123");
|
||||
testu("%3u", 1234, "1234");
|
||||
testu("%3u", 12345, "12345");
|
||||
testu("%3u", 32767, "32767");
|
||||
testu("%3u", 32768, "32768");
|
||||
testu("%3u", 65535, "65535");
|
||||
testu("%3x", 0, " 0");
|
||||
testu("%3x", 0x49bf, "49bf");
|
||||
testu("%3x", 0xffff, "ffff");
|
||||
testu("%3X", 0x49bf, "49BF");
|
||||
testu("%3X", 0xffff, "FFFF");
|
||||
|
||||
testu("%03u", 0, "000");
|
||||
testu("%03u", 1, "001");
|
||||
testu("%03u", 12, "012");
|
||||
testu("%03u", 123, "123");
|
||||
testu("%03u", 1234, "1234");
|
||||
testu("%03u", 12345, "12345");
|
||||
testu("%03u", 32767, "32767");
|
||||
testu("%03u", 32768, "32768");
|
||||
testu("%03u", 65535, "65535");
|
||||
testu("%03x", 0, "000");
|
||||
testu("%03x", 0x49bf, "49bf");
|
||||
testu("%03x", 0xffff, "ffff");
|
||||
testu("%03X", 0x49bf, "49BF");
|
||||
testu("%03X", 0xffff, "FFFF");
|
||||
|
||||
testu("%-4u", 0, "0 ");
|
||||
testu("%-4u", 1, "1 ");
|
||||
testu("%-4u", 12, "12 ");
|
||||
testu("%-4u", 123, "123 ");
|
||||
testu("%-4u", 1234, "1234");
|
||||
testu("%-4u", 12345, "12345");
|
||||
testu("%-4u", 32767, "32767");
|
||||
testu("%-4u", 32768, "32768");
|
||||
testu("%-4u", 65535, "65535");
|
||||
testu("%-4x", 0, "0 ");
|
||||
testu("%-4x", 0x49bf, "49bf");
|
||||
testu("%-4x", 0xffff, "ffff");
|
||||
testu("%-4X", 0x49bf, "49BF");
|
||||
testu("%-4X", 0xffff, "FFFF");
|
||||
|
||||
testul("%3lu", 0l, " 0");
|
||||
testul("%3lu", 1l, " 1");
|
||||
testul("%3lu", 12l, " 12");
|
||||
testul("%3lu", 123l, "123");
|
||||
testul("%3lu", 1234l, "1234");
|
||||
testul("%3lu", 12345l, "12345");
|
||||
testul("%3lu", 32767l, "32767");
|
||||
testul("%3lu", 2147483647l, "2147483647");
|
||||
testul("%3lu", 4294967295l, "4294967295");
|
||||
testul("%3lx", 0, " 0");
|
||||
testul("%3lx", 0x3576fbcdl, "3576fbcd");
|
||||
testul("%3lx", 0xffffffffl, "ffffffff");
|
||||
testul("%3lX", 0x3576fbcdl, "3576FBCD");
|
||||
testul("%3lX", 0xffffffffl, "FFFFFFFF");
|
||||
|
||||
testul("%03lu", 0l, "000");
|
||||
testul("%03lu", 1l, "001");
|
||||
testul("%03lu", 12l, "012");
|
||||
testul("%03lu", 123l, "123");
|
||||
testul("%03lu", 1234l, "1234");
|
||||
testul("%03lu", 12345l, "12345");
|
||||
testul("%03lu", 32767l, "32767");
|
||||
testul("%03lu", 2147483647l, "2147483647");
|
||||
testul("%03lu", 4294967295l, "4294967295");
|
||||
testul("%03lx", 0, "000");
|
||||
testul("%03lx", 0x3576fbcdl, "3576fbcd");
|
||||
testul("%03lx", 0xffffffffl, "ffffffff");
|
||||
testul("%03lX", 0x3576fbcdl, "3576FBCD");
|
||||
testul("%03lX", 0xffffffffl, "FFFFFFFF");
|
||||
|
||||
testul("%-4lu", 0l, "0 ");
|
||||
testul("%-4lu", 1l, "1 ");
|
||||
testul("%-4lu", 12l, "12 ");
|
||||
testul("%-4lu", 123l, "123 ");
|
||||
testul("%-4lu", 1234l, "1234");
|
||||
testul("%-4lu", 12345l, "12345");
|
||||
testul("%-4lu", 32767l, "32767");
|
||||
testul("%-4lu", 2147483647l, "2147483647");
|
||||
testul("%-4lu", 4294967295l, "4294967295");
|
||||
testul("%-4lx", 0, "0 ");
|
||||
testul("%-4lx", 0x3576fbcdl, "3576fbcd");
|
||||
testul("%-4lx", 0xffffffffl, "ffffffff");
|
||||
testul("%-4lX", 0x3576fbcdl, "3576FBCD");
|
||||
testul("%-4lX", 0xffffffffl, "FFFFFFFF");
|
||||
|
||||
testul("%+lu", 0l, "+0");
|
||||
testul("%+lu", 1l, "+1");
|
||||
testul("%+lu", 12l, "+12");
|
||||
testul("%+lu", 123l, "+123");
|
||||
testul("%+lu", 1234l, "+1234");
|
||||
testul("%+lu", 12345l, "+12345");
|
||||
testul("%+lu", 32767l, "+32767");
|
||||
testul("%+lu", 2147483647l, "+2147483647");
|
||||
testul("%+lu", 4294967295l, "+4294967295");
|
||||
|
||||
testf("%f", 0., "0.000000");
|
||||
testf("%f", 1., "1.000000");
|
||||
testf("%f", -1., "-1.000000");
|
||||
testf("%f", 12., "12.000000");
|
||||
testf("%f", 123., "123.000000");
|
||||
testf("%f", 1234., "1234.000000");
|
||||
testf("%f", 12345., "12345.000000");
|
||||
testf("%f", 123456., "123456.000000");
|
||||
testf("%f", 1234567., "1234567.000000");
|
||||
testf("%f", 0.1, "0.100000");
|
||||
testf("%f", 0.01, "0.010000");
|
||||
testf("%f", 0.001, "0.001000");
|
||||
testf("%f", 0.0001, "0.000100");
|
||||
testf("%f", 0.00001, "0.000010");
|
||||
testf("%f", 0.000001, "0.000001");
|
||||
|
||||
testf("%5.1f", 0, " 0.0");
|
||||
testf("%5.1f", 1, " 1.0");
|
||||
testf("%5.1f", -1, " -1.0");
|
||||
testf("%5.1f", 10, " 10.0");
|
||||
testf("%5.1f", -10, "-10.0");
|
||||
testf("%5.1f", 100, "100.0");
|
||||
testf("%5.1f", -100, "-100.0");
|
||||
testf("%5.1f", 0.1, " 0.1");
|
||||
testf("%5.1f", -0.1, " -0.1");
|
||||
testf("%5.1f", 0.04, " 0.0");
|
||||
testf("%5.1f", -0.04, " -0.0");
|
||||
testf("%5.1f", 0.051, " 0.1");
|
||||
testf("%5.1f", -0.051, " -0.1");
|
||||
|
||||
testf("%+5.1f", 0, " +0.0");
|
||||
testf("%+5.1f", 1, " +1.0");
|
||||
testf("%+5.1f", -1, " -1.0");
|
||||
testf("%+5.1f", 10, "+10.0");
|
||||
testf("%+5.1f", -10, "-10.0");
|
||||
testf("%+5.1f", 100, "+100.0");
|
||||
testf("%+5.1f", -100, "-100.0");
|
||||
testf("%+5.1f", 0.1, " +0.1");
|
||||
testf("%+5.1f", -0.1, " -0.1");
|
||||
testf("%+5.1f", 0.04, " +0.0");
|
||||
testf("%+5.1f", -0.04, " -0.0");
|
||||
testf("%+5.1f", 0.051, " +0.1");
|
||||
testf("%+5.1f", -0.051, " -0.1");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
#define EPSILON 0.0001
|
||||
|
||||
int scan_i(const char * fmt, const char * tst) {
|
||||
int val;
|
||||
|
||||
sscanf(tst, fmt, &val);
|
||||
printf(fmt, val);
|
||||
puts("\n");
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
long scan_l(const char * fmt, const char * tst) {
|
||||
long val;
|
||||
|
||||
sscanf(tst, fmt, &val);
|
||||
printf(fmt, val);
|
||||
puts("\n");
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
unsigned int scan_ui(const char * fmt, const char * tst) {
|
||||
unsigned int val;
|
||||
|
||||
sscanf(tst, fmt, &val);
|
||||
printf(fmt, val);
|
||||
puts("\n");
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
unsigned long scan_ul(const char * fmt, const char * tst) {
|
||||
unsigned long val;
|
||||
|
||||
sscanf(tst, fmt, &val);
|
||||
printf(fmt, val);
|
||||
puts("\n");
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
float scan_f(const char * fmt, const char * tst) {
|
||||
float val;
|
||||
|
||||
sscanf(tst, fmt, &val);
|
||||
printf(fmt, val);
|
||||
puts("\n");
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
bool closeTo(float a, float b) {
|
||||
while (a < -1.0 || a > 1.0) a /= 10.0;
|
||||
while (b < -1.0 || b > 1.0) b /= 10.0;
|
||||
|
||||
return fabs(a - b) < EPSILON;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
assert(scan_i("%d", "0") == 0);
|
||||
assert(scan_i("%d", "1") == 1);
|
||||
assert(scan_i("%d", "-1") == -1);
|
||||
assert(scan_i("%d", "12") == 12);
|
||||
assert(scan_i("%d", "123") == 123);
|
||||
assert(scan_i("%d", "1234") == 1234);
|
||||
assert(scan_i("%d", "12345") == 12345);
|
||||
assert(scan_i("%d", "-12345") == -12345);
|
||||
assert(scan_i("%d", "32767") == 32767);
|
||||
assert(scan_i("%d", "-32768") == -32768);
|
||||
|
||||
assert(scan_l("%ld", "0") == 0l);
|
||||
assert(scan_l("%ld", "1") == 1l);
|
||||
assert(scan_l("%ld", "-1") == -1l);
|
||||
assert(scan_l("%ld", "12") == 12l);
|
||||
assert(scan_l("%ld", "123") == 123l);
|
||||
assert(scan_l("%ld", "1234") == 1234l);
|
||||
assert(scan_l("%ld", "12345") == 12345l);
|
||||
assert(scan_l("%ld", "-12345") == -12345l);
|
||||
assert(scan_l("%ld", "32767") == 32767l);
|
||||
assert(scan_l("%ld", "-32768") == -32768l);
|
||||
assert(scan_l("%ld", "2147483647") == 2147483647l);
|
||||
assert(scan_l("%ld", "-2147483648") == -2147483648l);
|
||||
|
||||
assert(scan_ui("%u", "0") == 0);
|
||||
assert(scan_ui("%u", "1") == 1);
|
||||
assert(scan_ui("%u", "12") == 12);
|
||||
assert(scan_ui("%u", "123") == 123);
|
||||
assert(scan_ui("%u", "1234") == 1234);
|
||||
assert(scan_ui("%u", "12345") == 12345);
|
||||
assert(scan_ui("%u", "32767") == 32767);
|
||||
assert(scan_ui("%u", "32768") == 32768);
|
||||
assert(scan_ui("%u", "65535") == 65535);
|
||||
assert(scan_ui("%x", "0") == 0);
|
||||
assert(scan_ui("%x", "49BF") == 0x49bf);
|
||||
assert(scan_ui("%x", "FFFF") == 0xffff);
|
||||
|
||||
assert(scan_ul("%lu", "000") == 0l);
|
||||
assert(scan_ul("%lu", "001") == 1l);
|
||||
assert(scan_ul("%lu", "012") == 12l);
|
||||
assert(scan_ul("%lu", "123") == 123l);
|
||||
assert(scan_ul("%lu", "1234") == 1234l);
|
||||
assert(scan_ul("%lu", "12345") == 12345l);
|
||||
assert(scan_ul("%lu", "32767") == 32767l);
|
||||
assert(scan_ul("%lu", "2147483647") == 2147483647l);
|
||||
assert(scan_ul("%lu", "4294967295") == 4294967295l);
|
||||
assert(scan_ul("%lx", "000") == 0);
|
||||
assert(scan_ul("%lx", "3576FBCD") == 0x3576fbcdl);
|
||||
assert(scan_ul("%lx", "FFFFFFFF") == 0xffffffffl);
|
||||
|
||||
assert(closeTo(scan_f("%f", "0.000000"), 0.));
|
||||
assert(closeTo(scan_f("%f", "1.000000"), 1.));
|
||||
assert(closeTo(scan_f("%f", "-1.000000"), -1.));
|
||||
assert(closeTo(scan_f("%f", "12.000000"), 12.));
|
||||
assert(closeTo(scan_f("%f", "123.000000"), 123.));
|
||||
assert(closeTo(scan_f("%f", "1234.000000"), 1234.));
|
||||
assert(closeTo(scan_f("%f", "12345.000000"), 12345.));
|
||||
assert(closeTo(scan_f("%f", "123456.000000"), 123456.));
|
||||
assert(closeTo(scan_f("%f", "1234567.000000"), 1234567.));
|
||||
assert(closeTo(scan_f("%f", "0.100000"), 0.1));
|
||||
assert(closeTo(scan_f("%f", "0.010000"), 0.01));
|
||||
assert(closeTo(scan_f("%f", "0.001000"), 0.001));
|
||||
assert(closeTo(scan_f("%f", "0.000100"), 0.0001));
|
||||
assert(closeTo(scan_f("%f", "0.000010"), 0.00001));
|
||||
assert(closeTo(scan_f("%f", "0.000001"), 0.000001));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
static const int size = 100;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int a[size];
|
||||
|
||||
for(int i=0; i<size; i++)
|
||||
a[i] = i;
|
||||
|
||||
int s = 0;
|
||||
for(int i=0; i<size; i++)
|
||||
s += a[i];
|
||||
|
||||
assert(s == 4950);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
// stdlibtest
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
|
||||
void numcheck(int n)
|
||||
{
|
||||
char buffer[10];
|
||||
itoa(n, buffer, 10);
|
||||
int m = atoi(buffer);
|
||||
|
||||
printf("%d : %s -> %d\n", n, buffer, m);
|
||||
|
||||
if (m != n)
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
void numchecks(void)
|
||||
{
|
||||
numcheck(0);
|
||||
numcheck(-1);
|
||||
numcheck(1);
|
||||
numcheck(12345);
|
||||
numcheck(-12345);
|
||||
numcheck(INT_MIN);
|
||||
numcheck(INT_MAX);
|
||||
}
|
||||
|
||||
void heapcheck(void)
|
||||
{
|
||||
void * memp[100];
|
||||
int mems[100];
|
||||
int n, k, s, i;
|
||||
|
||||
for(n=0; n<100; n++)
|
||||
{
|
||||
s = rand() % 100 + 3;
|
||||
mems[n] = s;
|
||||
memp[n] = malloc(s);
|
||||
memset(memp[n], n, s);
|
||||
}
|
||||
|
||||
for(k=0; k<1000; k++)
|
||||
{
|
||||
n = rand() % 100;
|
||||
int s = mems[n];
|
||||
char * p = memp[n];
|
||||
for(i=0; i<s; i++)
|
||||
{
|
||||
if (p[i] != n)
|
||||
exit(-2);
|
||||
}
|
||||
free(memp[n]);
|
||||
|
||||
s = rand() % 100 + 3;
|
||||
mems[n] = s;
|
||||
memp[n] = malloc(s);
|
||||
if (!memp[n])
|
||||
exit(-3);
|
||||
memset(memp[n], n, s);
|
||||
}
|
||||
}
|
||||
|
||||
void callocckeck(void) {
|
||||
static const int ALLOC_COUNT = 4;
|
||||
static const int MAX_SIZE = 8;
|
||||
|
||||
int i, j;
|
||||
int sizes[ALLOC_COUNT];
|
||||
char str[ALLOC_COUNT][2 * MAX_SIZE];
|
||||
void *ptr[ALLOC_COUNT];
|
||||
|
||||
for (i = 0; i < ALLOC_COUNT; i++)
|
||||
{
|
||||
sizes[i] = (rand() % MAX_SIZE + 1) * 2;
|
||||
|
||||
for (j=0; j < sizes[i]-1; j++) {
|
||||
str[i][j] = 'a' + rand() % 26;
|
||||
}
|
||||
|
||||
str[i][sizes[i]-1] = '\0';
|
||||
}
|
||||
|
||||
for (i = 0; i < ALLOC_COUNT; i++)
|
||||
{
|
||||
ptr[i] = calloc(sizes[i] / 2, 2);
|
||||
|
||||
if (ptr[i] == NULL)
|
||||
{
|
||||
exit(-4);
|
||||
}
|
||||
|
||||
strcpy(ptr[i], str[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < ALLOC_COUNT; i++)
|
||||
{
|
||||
if (strcmp(ptr[i], str[i]) != 0)
|
||||
{
|
||||
exit(-5);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < ALLOC_COUNT; i++)
|
||||
{
|
||||
free(ptr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void divcheck(void) {
|
||||
div_t d = div(10, 3);
|
||||
if (d.quot != 3 || d.rem != 1)
|
||||
exit(-6);
|
||||
|
||||
ldiv_t ld = ldiv(10, 3);
|
||||
if (ld.quot != 3 || ld.rem != 1)
|
||||
exit(-7);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
numchecks();
|
||||
heapcheck();
|
||||
callocckeck();
|
||||
divcheck();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char dest[2000], src[2000];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Test strcat with basic strings
|
||||
memset(dest, '#', sizeof(dest));
|
||||
strcpy(dest, "hello");
|
||||
strcat(dest, " world");
|
||||
assert(strcmp(dest, "hello world") == 0);
|
||||
|
||||
// Test strcat with empty string
|
||||
memset(dest, '#', sizeof(dest));
|
||||
strcpy(dest, "test");
|
||||
strcat(dest, "");
|
||||
assert(strcmp(dest, "test") == 0);
|
||||
|
||||
// Test strcat to empty string
|
||||
memset(dest, '#', sizeof(dest));
|
||||
strcpy(dest, "");
|
||||
strcat(dest, "append");
|
||||
assert(strcmp(dest, "append") == 0);
|
||||
|
||||
// Test strcat multiple concatenations
|
||||
memset(dest, '#', sizeof(dest));
|
||||
strcpy(dest, "a");
|
||||
strcat(dest, "b");
|
||||
strcat(dest, "c");
|
||||
strcat(dest, "d");
|
||||
assert(strcmp(dest, "abcd") == 0);
|
||||
|
||||
// Test strcat with single characters
|
||||
memset(dest, '#', sizeof(dest));
|
||||
strcpy(dest, "x");
|
||||
strcat(dest, "y");
|
||||
assert(strcmp(dest, "xy") == 0);
|
||||
|
||||
// Test strcat with longer strings
|
||||
memset(dest, '#', sizeof(dest));
|
||||
strcpy(dest, "beginning");
|
||||
strcat(dest, "_middle_");
|
||||
strcat(dest, "end");
|
||||
assert(strcmp(dest, "beginning_middle_end") == 0);
|
||||
|
||||
// Test strncat with basic functionality
|
||||
memset(dest, '#', sizeof(dest));
|
||||
strcpy(dest, "hello");
|
||||
strncat(dest, " world", 6);
|
||||
assert(memcmp(dest, "hello world\0#", 13) == 0);
|
||||
|
||||
// Test strncat with partial concatenation
|
||||
memset(dest, '#', sizeof(dest));
|
||||
strcpy(dest, "hello");
|
||||
strncat(dest, " world", 3);
|
||||
assert(memcmp(dest, "hello wo\0#", 10) == 0);
|
||||
|
||||
// Test strncat with zero length
|
||||
memset(dest, '#', sizeof(dest));
|
||||
strcpy(dest, "original");
|
||||
strncat(dest, "ignored", 0);
|
||||
assert(memcmp(dest, "original\0#", 10) == 0);
|
||||
|
||||
// Test strncat with exact length
|
||||
memset(dest, '#', sizeof(dest));
|
||||
strcpy(dest, "test");
|
||||
strncat(dest, "1234", 4);
|
||||
assert(memcmp(dest, "test1234\0#", 10) == 0);
|
||||
|
||||
// Test strncat where n is larger than source
|
||||
memset(dest, '#', sizeof(dest));
|
||||
strcpy(dest, "base");
|
||||
strncat(dest, "add", 10);
|
||||
assert(memcmp(dest, "baseadd\0#", 9) == 0);
|
||||
|
||||
// Test strncat with empty source
|
||||
memset(dest, '#', sizeof(dest));
|
||||
strcpy(dest, "keep");
|
||||
strncat(dest, "", 5);
|
||||
assert(memcmp(dest, "keep\0#", 6) == 0);
|
||||
|
||||
// Test strncat with empty destination
|
||||
memset(dest, '#', sizeof(dest));
|
||||
strcpy(dest, "");
|
||||
strncat(dest, "new", 3);
|
||||
assert(memcmp(dest, "new\0#", 4) == 0);
|
||||
|
||||
// Test strncat with single character
|
||||
memset(dest, '#', sizeof(dest));
|
||||
strcpy(dest, "a");
|
||||
strncat(dest, "bcdef", 1);
|
||||
assert(memcmp(dest, "ab\0#", 4) == 0);
|
||||
|
||||
// Test strncat with long strings
|
||||
memset(dest, '#', sizeof(dest));
|
||||
for (int i = 0; i < 500; i++)
|
||||
{
|
||||
src[i] = 'a' + (i & 7);
|
||||
}
|
||||
src[500] = '\0';
|
||||
|
||||
strcpy(dest, "prefix_");
|
||||
strcat(dest, src);
|
||||
assert(strlen(dest) == 507); // 7 + 500
|
||||
assert(strncmp(dest, "prefix_", 7) == 0);
|
||||
assert(memcmp(dest + 7, src, 500) == 0);
|
||||
|
||||
// Test strncat with long strings
|
||||
memset(dest, '#', sizeof(dest));
|
||||
strcpy(dest, "start_");
|
||||
strncat(dest, src, 100);
|
||||
assert(strlen(dest) == 106); // 6 + 100
|
||||
assert(strncmp(dest, "start_", 6) == 0);
|
||||
assert(strncmp(dest + 6, src, 100) == 0);
|
||||
assert(dest[106] == '\0'); // ensure null termination
|
||||
|
||||
// Test strncat with partial long string
|
||||
memset(dest, '#', sizeof(dest));
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
src[i] = 'x' + (i & 3);
|
||||
}
|
||||
src[1000] = '\0';
|
||||
|
||||
strcpy(dest, "begin");
|
||||
strncat(dest, src, 50);
|
||||
assert(strlen(dest) == 55); // 5 + 50
|
||||
assert(strncmp(dest, "begin", 5) == 0);
|
||||
assert(strncmp(dest + 5, src, 50) == 0);
|
||||
assert(dest[55] == '\0'); // ensure null termination
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char teststr[2000];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Test strchr with basic functionality
|
||||
assert(strcmp(strchr("hello", 'h'), "hello") == 0);
|
||||
assert(strcmp(strchr("hello", 'e'), "ello") == 0);
|
||||
assert(strcmp(strchr("hello", 'l'), "llo") == 0); // finds first 'l'
|
||||
assert(strcmp(strchr("hello", 'o'), "o") == 0);
|
||||
assert(strchr("hello", 'x') == nullptr);
|
||||
|
||||
// Test strchr with null character
|
||||
strcpy(teststr, "hello");
|
||||
assert(strchr(teststr, '\0') == teststr + 5); // should point to end of string
|
||||
|
||||
// Test strchr with empty string
|
||||
assert(strchr("", 'a') == nullptr);
|
||||
strcpy(teststr, "");
|
||||
assert(strchr(teststr, '\0') == teststr); // should point to start of
|
||||
|
||||
// Test strchr with single character string
|
||||
assert(strcmp(strchr("a", 'a'), "a") == 0);
|
||||
assert(strchr("a", 'b') == nullptr);
|
||||
strcpy(teststr, "a");
|
||||
assert(strchr(teststr, '\0') == teststr + 1); // should point to end of single character string
|
||||
|
||||
// Test strchr with repeated characters
|
||||
assert(strcmp(strchr("aaaaaa", 'a'), "aaaaaa") == 0); // finds first occurrence
|
||||
assert(strcmp(strchr("abcabc", 'a'), "abcabc") == 0); // finds first 'a'
|
||||
assert(strcmp(strchr("abcabc", 'b'), "bcabc") == 0); // finds first 'b'
|
||||
assert(strcmp(strchr("abcabc", 'c'), "cabc") == 0); // finds first 'c'
|
||||
|
||||
// Test strchr with special characters
|
||||
assert(strcmp(strchr("hello world", ' '), " world") == 0);
|
||||
assert(strcmp(strchr("a.b,c;d", '.'), ".b,c;d") == 0);
|
||||
assert(strcmp(strchr("a.b,c;d", ','), ",c;d") == 0);
|
||||
assert(strcmp(strchr("a.b,c;d", ';'), ";d") == 0);
|
||||
|
||||
// Test strrchr with basic functionality
|
||||
assert(strcmp(strrchr("hello", 'h'), "hello") == 0);
|
||||
assert(strcmp(strrchr("hello", 'e'), "ello") == 0);
|
||||
assert(strcmp(strrchr("hello", 'l'), "lo") == 0); // finds last 'l'
|
||||
assert(strcmp(strrchr("hello", 'o'), "o") == 0);
|
||||
assert(strrchr("hello", 'x') == nullptr);
|
||||
|
||||
// Test strrchr with null character
|
||||
strcpy(teststr, "hello");
|
||||
assert(strrchr(teststr, '\0') == teststr + 5); // should point to end of string
|
||||
|
||||
// Test strrchr with empty string
|
||||
assert(strrchr("", 'a') == nullptr);
|
||||
strcpy(teststr, "");
|
||||
assert(strrchr(teststr, '\0') == teststr); // should point to start
|
||||
|
||||
// Test strrchr with single character string
|
||||
assert(strcmp(strrchr("a", 'a'), "a") == 0);
|
||||
assert(strrchr("a", 'b') == nullptr); // Test strrchr with repeated characters
|
||||
assert(strcmp(strrchr("aaaaaa", 'a'), "a") == 0); // finds last 'a'
|
||||
assert(strcmp(strrchr("abcabc", 'a'), "abc") == 0); // finds last 'a'
|
||||
assert(strcmp(strrchr("abcabc", 'b'), "bc") == 0); // finds last 'b'
|
||||
assert(strcmp(strrchr("abcabc", 'c'), "c") == 0); // finds last 'c'
|
||||
|
||||
// Test strrchr with special characters
|
||||
assert(strcmp(strrchr("hello world test", ' '), " test") == 0);
|
||||
assert(strcmp(strrchr("a.b.c.d", '.'), ".d") == 0);
|
||||
assert(strcmp(strrchr("a,b,c,d", ','), ",d") == 0);
|
||||
|
||||
// Test with longer strings
|
||||
strcpy(teststr, "this is a test string with multiple a characters");
|
||||
assert(strchr(teststr, 'a') == teststr + 8); // first 'a' at position 8
|
||||
assert(strrchr(teststr, 'a') == teststr + 42); // last 'a' at position 42
|
||||
|
||||
// Test with character not found in long string
|
||||
assert(strchr(teststr, 'z') == nullptr);
|
||||
assert(strrchr(teststr, 'z') == nullptr);
|
||||
|
||||
// Test with first and last character
|
||||
strcpy(teststr, "abcdefghijklmnopqrstuvwxyza");
|
||||
assert(strchr(teststr, 'a') == teststr); // first character
|
||||
assert(strrchr(teststr, 'a') == teststr + 26); // last character
|
||||
|
||||
// Build a long test string with pattern
|
||||
for(int i = 0; i < 1000; i++)
|
||||
{
|
||||
teststr[i] = 'a' + (i % 26);
|
||||
}
|
||||
teststr[1000] = '\0';
|
||||
|
||||
// Test strchr and strrchr with pattern
|
||||
assert(strchr(teststr, 'a') == teststr); // first 'a' at start
|
||||
assert(strchr(teststr, 'z') == teststr + 25); // first 'z' at position 25
|
||||
assert(strrchr(teststr, 'a') == teststr + 988); // last 'a' at 988 (988 % 26 == 0)
|
||||
assert(strrchr(teststr, 'z') == teststr + 987); // last 'z' at 987 (987 % 26 == 25)
|
||||
|
||||
// Test with character that appears only once
|
||||
strcpy(teststr, "abcdefghijklmnopqrstuvwxyz");
|
||||
for(char c = 'a'; c <= 'z'; c++)
|
||||
{
|
||||
char *first = strchr(teststr, c);
|
||||
char *last = strrchr(teststr, c);
|
||||
assert(first == last); // should be same for unique characters
|
||||
assert(first != nullptr);
|
||||
assert(*first == c);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
assert(strcmp("ABCD", "ABCD") == 0);
|
||||
assert(strcmp("ABCE", "ABCD") == 1);
|
||||
assert(strcmp("ABCD", "ABCE") == -1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
char aa[2000], ba[2000];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
assert(strcmp("abcdefgh", "abcdefgh") == 0);
|
||||
assert(strcmp("abcdefgh", "abcdemgh") < 0);
|
||||
assert(strcmp("abcdefgh", "abcdefghi") < 0);
|
||||
assert(strcmp("abcdefghi", "abcdefgh") > 0);
|
||||
assert(strcmp("abcdemgh", "abcdefgh") > 0);
|
||||
|
||||
for(int i=0; i<1900; i++)
|
||||
{
|
||||
aa[i] = 'a' + (i & 7);
|
||||
}
|
||||
aa[1900] = 0;
|
||||
|
||||
strcpy(ba, aa);
|
||||
|
||||
assert(strcmp(aa, ba) == 0);
|
||||
ba[1000] = 'z';
|
||||
assert(strcmp(aa, ba) < 0);
|
||||
assert(strcmp(ba, aa) > 0);
|
||||
|
||||
// Test strncmp with basic comparisons
|
||||
assert(strncmp("abcdefgh", "abcdefgh", 8) == 0);
|
||||
assert(strncmp("abcdefgh", "abcdemgh", 8) < 0);
|
||||
assert(strncmp("abcdefgh", "abcdefghi", 8) == 0); // only compare first 8 chars
|
||||
assert(strncmp("abcdefghi", "abcdefgh", 9) > 0);
|
||||
assert(strncmp("abcdemgh", "abcdefgh", 8) > 0);
|
||||
|
||||
// Test strncmp with partial comparisons
|
||||
assert(strncmp("abcdefgh", "abcdemgh", 4) == 0); // first 4 chars are same
|
||||
assert(strncmp("abcdefgh", "abcdemgh", 6) < 0); // difference at 5th char
|
||||
assert(strncmp("hello", "help", 3) == 0); // "hel" vs "hel"
|
||||
assert(strncmp("hello", "help", 4) < 0); // "hell" vs "help"
|
||||
|
||||
// Test strncmp with zero length
|
||||
assert(strncmp("different", "strings", 0) == 0); // zero length always equal
|
||||
assert(strncmp("", "", 0) == 0);
|
||||
assert(strncmp("a", "b", 0) == 0);
|
||||
|
||||
// Test strncmp with empty strings
|
||||
assert(strncmp("", "", 5) == 0);
|
||||
assert(strncmp("hello", "", 5) > 0);
|
||||
assert(strncmp("", "hello", 5) < 0);
|
||||
assert(strncmp("hello", "", 1) > 0);
|
||||
assert(strncmp("", "hello", 1) < 0);
|
||||
|
||||
// Test strncmp with single characters
|
||||
assert(strncmp("a", "a", 1) == 0);
|
||||
assert(strncmp("a", "b", 1) < 0);
|
||||
assert(strncmp("b", "a", 1) > 0);
|
||||
|
||||
// Test strncmp where one string is shorter
|
||||
assert(strncmp("abc", "abcdef", 3) == 0);
|
||||
assert(strncmp("abc", "abcdef", 6) < 0); // null vs 'd'
|
||||
assert(strncmp("abcdef", "abc", 6) > 0); // 'd' vs null
|
||||
|
||||
// Test strncmp with long strings
|
||||
strcpy(ba, aa); // restore ba to match aa
|
||||
assert(strncmp(aa, ba, 1900) == 0);
|
||||
ba[1000] = 'z';
|
||||
assert(strncmp(aa, ba, 1000) == 0); // equal up to position 1000
|
||||
assert(strncmp(aa, ba, 1001) < 0); // difference at position 1000
|
||||
assert(strncmp(ba, aa, 1001) > 0); // difference at position 1000
|
||||
assert(strncmp(aa, ba, 999) == 0); // equal before the difference
|
||||
|
||||
// Test strncmp with length larger than string length
|
||||
strcpy(ba, "short");
|
||||
assert(strncmp("short", ba, 100) == 0); // equal even with large n
|
||||
assert(strncmp("short", "shorx", 100) < 0); // difference within string
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char dest[1025], src[1025];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
strcpy(dest, "hello");
|
||||
assert(strcmp(dest, "hello") == 0);
|
||||
|
||||
strcpy(dest, "");
|
||||
assert(strcmp(dest, "") == 0);
|
||||
|
||||
strcpy(dest, "a");
|
||||
assert(strcmp(dest, "a") == 0);
|
||||
|
||||
strcpy(dest, "abcdefghijklmnopqrstuvwxyz");
|
||||
assert(strcmp(dest, "abcdefghijklmnopqrstuvwxyz") == 0);
|
||||
|
||||
// Test strcpy with long string
|
||||
for (int i = 0; i < 1024; i++)
|
||||
{
|
||||
src[i] = 'a' + (i & 7);
|
||||
}
|
||||
src[1024] = 0;
|
||||
|
||||
strcpy(dest, src);
|
||||
assert(strcmp(dest, src) == 0);
|
||||
|
||||
// Test strncpy with various lengths
|
||||
strcpy(dest, "xxxxxxxxxx");
|
||||
strncpy(dest, "hello", 5);
|
||||
dest[5] = 0; // null terminate for comparison
|
||||
assert(strcmp(dest, "hello") == 0);
|
||||
|
||||
strcpy(dest, "xxxxxxxxxx");
|
||||
strncpy(dest, "hello", 3);
|
||||
dest[3] = 0; // null terminate for comparison
|
||||
assert(strcmp(dest, "hel") == 0);
|
||||
|
||||
strcpy(dest, "xxxxxxxxxx");
|
||||
strncpy(dest, "hi", 5);
|
||||
assert(dest[0] == 'h');
|
||||
assert(dest[1] == 'i');
|
||||
assert(dest[2] == 0);
|
||||
assert(dest[3] == 0);
|
||||
assert(dest[4] == 0);
|
||||
|
||||
// Test strncpy with exact length
|
||||
strcpy(dest, "xxxxxxxxxx");
|
||||
strncpy(dest, "test", 4);
|
||||
dest[4] = 0; // null terminate for comparison
|
||||
assert(strcmp(dest, "test") == 0);
|
||||
|
||||
// Test strncpy with zero length
|
||||
strcpy(dest, "original");
|
||||
strncpy(dest, "new", 0);
|
||||
assert(strcmp(dest, "original") == 0);
|
||||
|
||||
// Test strncpy copying longer than source
|
||||
strcpy(dest, "xxxxxxxxxx");
|
||||
strncpy(dest, "ab", 8);
|
||||
assert(dest[0] == 'a');
|
||||
assert(dest[1] == 'b');
|
||||
assert(dest[2] == 0);
|
||||
assert(dest[3] == 0);
|
||||
assert(dest[4] == 0);
|
||||
assert(dest[5] == 0);
|
||||
assert(dest[6] == 0);
|
||||
assert(dest[7] == 0);
|
||||
|
||||
// Test strncpy with large string
|
||||
strcpy(dest, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
|
||||
strncpy(dest, src, 1000);
|
||||
dest[1000] = 0; // ensure null termination
|
||||
src[1000] = 0; // truncate source for comparison
|
||||
assert(strcmp(dest, src) == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
int a100[100];
|
||||
__striped int b100[100];
|
||||
__striped int c100[100];
|
||||
|
||||
unsigned a256[256];
|
||||
__striped unsigned b256[256];
|
||||
__striped unsigned c256[256];
|
||||
|
||||
#pragma align(c100, 256)
|
||||
#pragma align(c256, 256)
|
||||
|
||||
void test_ab100(void)
|
||||
{
|
||||
for(char i=0; i<100; i++)
|
||||
{
|
||||
a100[i] = i * i;
|
||||
b100[i] = i * i;
|
||||
c100[i] = i * i;
|
||||
}
|
||||
|
||||
a100[31] = 4711;
|
||||
b100[31] = 4711;
|
||||
c100[31] = 4711;
|
||||
|
||||
|
||||
for(char i=0; i<100; i++)
|
||||
{
|
||||
a100[i] += i; a100[i] -= 5; a100[i] = a100[i] + a100[99 - i];
|
||||
b100[i] += i; b100[i] -= 5; b100[i] = b100[i] + b100[99 - i];
|
||||
c100[i] += i; c100[i] -= 5; c100[i] = c100[i] + c100[99 - i];
|
||||
}
|
||||
|
||||
for(char i=0; i<100; i++)
|
||||
{
|
||||
assert(a100[i] == b100[i]);
|
||||
assert(a100[i] == c100[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void test_ab256(void)
|
||||
{
|
||||
for(unsigned i=0; i<256; i++)
|
||||
{
|
||||
a256[i] = i * i;
|
||||
b256[i] = i * i;
|
||||
c256[i] = i * i;
|
||||
}
|
||||
|
||||
a256[31] = 4711;
|
||||
b256[31] = 4711;
|
||||
c256[31] = 4711;
|
||||
|
||||
for(unsigned i=0; i<256; i++)
|
||||
{
|
||||
a256[i] += i; a256[i] -= 5; a256[i] = a256[i] + a256[255 - i];
|
||||
b256[i] += i; b256[i] -= 5; b256[i] = b256[i] + b256[255 - i];
|
||||
c256[i] += i; c256[i] -= 5; c256[i] = c256[i] + c256[255 - i];
|
||||
}
|
||||
|
||||
for(unsigned i=0; i<256; i++)
|
||||
{
|
||||
assert(a256[i] == b256[i]);
|
||||
assert(a256[i] == c256[i]);
|
||||
}
|
||||
}
|
||||
|
||||
long la50[50];
|
||||
__striped long lb50[50];
|
||||
__striped long lc50[50];
|
||||
|
||||
unsigned long la256[256];
|
||||
__striped unsigned long lb256[256];
|
||||
__striped unsigned long lc256[256];
|
||||
|
||||
#pragma align(lc50, 256)
|
||||
#pragma align(lc256, 256)
|
||||
|
||||
void test_lab50(void)
|
||||
{
|
||||
for(char i=0; i<50; i++)
|
||||
{
|
||||
long j = i * i;
|
||||
la50[i] = j * j;
|
||||
lb50[i] = j * j;
|
||||
lc50[i] = j * j;
|
||||
}
|
||||
|
||||
la50[31] = 47110815l;
|
||||
lb50[31] = 47110815l;
|
||||
lc50[31] = 47110815l;
|
||||
|
||||
for(char i=0; i<50; i++)
|
||||
{
|
||||
la50[i] += i; la50[i] -= 12345678l; la50[i] = la50[i] + la50[49 - i];
|
||||
lb50[i] += i; lb50[i] -= 12345678l; lb50[i] = lb50[i] + lb50[49 - i];
|
||||
lc50[i] += i; lc50[i] -= 12345678l; lc50[i] = lc50[i] + lc50[49 - i];
|
||||
}
|
||||
|
||||
for(char i=0; i<50; i++)
|
||||
{
|
||||
assert(la50[i] == lb50[i]);
|
||||
assert(la50[i] == lc50[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void test_lab256(void)
|
||||
{
|
||||
for(unsigned i=0; i<256; i++)
|
||||
{
|
||||
unsigned long j = i * i;
|
||||
la256[i] = j * j;
|
||||
lb256[i] = j * j;
|
||||
lc256[i] = j * j;
|
||||
}
|
||||
|
||||
la256[31] = 47110815ul;
|
||||
lb256[31] = 47110815ul;
|
||||
lc256[31] = 47110815ul;
|
||||
|
||||
for(unsigned i=0; i<256; i++)
|
||||
{
|
||||
la256[i] += i; la256[i] -= 12345678ul; la256[i] = la256[i] + la256[255 - i];
|
||||
lb256[i] += i; lb256[i] -= 12345678ul; lb256[i] = lb256[i] + lb256[255 - i];
|
||||
lc256[i] += i; lc256[i] -= 12345678ul; lc256[i] = lc256[i] + lc256[255 - i];
|
||||
}
|
||||
|
||||
for(unsigned i=0; i<256; i++)
|
||||
{
|
||||
assert(la256[i] == lb256[i]);
|
||||
assert(la256[i] == lc256[i]);
|
||||
}
|
||||
}
|
||||
|
||||
float fa50[50];
|
||||
__striped float fb50[50];
|
||||
__striped float fc50[50];
|
||||
|
||||
float fa256[256];
|
||||
__striped float fb256[256];
|
||||
__striped float fc256[256];
|
||||
|
||||
#pragma align(fc50, 256)
|
||||
#pragma align(fc256, 256)
|
||||
|
||||
void test_fab50(void)
|
||||
{
|
||||
for(char i=0; i<50; i++)
|
||||
{
|
||||
fa50[i] = i * i;
|
||||
fb50[i] = i * i;
|
||||
fc50[i] = i * i;
|
||||
}
|
||||
|
||||
fa50[31] = 4711.0815;
|
||||
fb50[31] = 4711.0815;
|
||||
fc50[31] = 4711.0815;
|
||||
|
||||
for(char i=0; i<50; i++)
|
||||
{
|
||||
fa50[i] += i; fa50[i] -= 1234.5678; fa50[i] = fa50[i] + fa50[49 - i];
|
||||
fb50[i] += i; fb50[i] -= 1234.5678; fb50[i] = fb50[i] + fb50[49 - i];
|
||||
fc50[i] += i; fc50[i] -= 1234.5678; fc50[i] = fc50[i] + fc50[49 - i];
|
||||
}
|
||||
|
||||
for(char i=0; i<50; i++)
|
||||
{
|
||||
assert(fa50[i] == fb50[i]);
|
||||
assert(fa50[i] == fc50[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void test_fab256(void)
|
||||
{
|
||||
for(unsigned i=0; i<256; i++)
|
||||
{
|
||||
fa256[i] = i * i;
|
||||
fb256[i] = i * i;
|
||||
fc256[i] = i * i;
|
||||
}
|
||||
|
||||
fa256[31] = 4711.0815;
|
||||
fb256[31] = 4711.0815;
|
||||
fc256[31] = 4711.0815;
|
||||
|
||||
for(unsigned i=0; i<256; i++)
|
||||
{
|
||||
fa256[i] += i; fa256[i] -= 1234.5678; fa256[i] = fa256[i] + fa256[255 - i];
|
||||
fb256[i] += i; fb256[i] -= 1234.5678; fb256[i] = fb256[i] + fb256[255 - i];
|
||||
fc256[i] += i; fc256[i] -= 1234.5678; fc256[i] = fc256[i] + fc256[255 - i];
|
||||
}
|
||||
|
||||
for(unsigned i=0; i<256; i++)
|
||||
{
|
||||
assert(fa256[i] == fb256[i]);
|
||||
assert(fa256[i] == fc256[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unsigned da50[50], db50[50], dc50[50];
|
||||
|
||||
unsigned * pa50[50];
|
||||
__striped unsigned * pb50[50];
|
||||
__striped unsigned * pc50[50];
|
||||
|
||||
#pragma align(pc50, 256)
|
||||
|
||||
void test_pab50(void)
|
||||
{
|
||||
for(char i=0; i<50; i++)
|
||||
{
|
||||
pa50[i] = da50 + (i * 17) % 50;
|
||||
pb50[i] = db50 + (i * 17) % 50;
|
||||
pc50[i] = dc50 + (i * 17) % 50;
|
||||
}
|
||||
|
||||
for(char i=0; i<50; i++)
|
||||
{
|
||||
*pa50[i] = i * i;
|
||||
*pb50[i] = i * i;
|
||||
*pc50[i] = i * i;
|
||||
}
|
||||
|
||||
for(char i=0; i<50; i++)
|
||||
{
|
||||
*pa50[i] += i; *pa50[i] -= 5; *pa50[i] = *pa50[i] + *pa50[49 - i];
|
||||
*pb50[i] += i; *pb50[i] -= 5; *pb50[i] = *pb50[i] + *pb50[49 - i];
|
||||
*pc50[i] += i; *pc50[i] -= 5; *pc50[i] = *pc50[i] + *pc50[49 - i];
|
||||
}
|
||||
|
||||
for(char i=0; i<50; i++)
|
||||
{
|
||||
assert(*pa50[i] == *pb50[i]);
|
||||
assert(*pa50[i] == *pc50[i]);
|
||||
assert(da50[i] == db50[i]);
|
||||
assert(da50[i] == dc50[i]);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned da50_4[50][4], db50_4[50][4], dc50_4[50][4];
|
||||
|
||||
void test_pab50_4(void)
|
||||
{
|
||||
for(char i=0; i<50; i++)
|
||||
{
|
||||
pa50[i] = da50_4[(i * 17) % 50];
|
||||
pb50[i] = db50_4[(i * 17) % 50];
|
||||
pc50[i] = dc50_4[(i * 17) % 50];
|
||||
}
|
||||
|
||||
for(char k=0; k<4; k++)
|
||||
{
|
||||
for(char i=0; i<50; i++)
|
||||
{
|
||||
pa50[i][k] = i * i;
|
||||
pb50[i][k] = i * i;
|
||||
pc50[i][k] = i * i;
|
||||
}
|
||||
}
|
||||
|
||||
for(char k=0; k<4; k++)
|
||||
{
|
||||
for(char i=0; i<50; i++)
|
||||
{
|
||||
pa50[i][k] += i; pa50[i][k] -= 5; pa50[i][k] = pa50[i][k] + pa50[49 - i][k];
|
||||
pb50[i][k] += i; pb50[i][k] -= 5; pb50[i][k] = pb50[i][k] + pb50[49 - i][k];
|
||||
pc50[i][k] += i; pc50[i][k] -= 5; pc50[i][k] = pc50[i][k] + pc50[49 - i][k];
|
||||
}
|
||||
}
|
||||
|
||||
for(char k=0; k<4; k++)
|
||||
{
|
||||
for(char i=0; i<50; i++)
|
||||
{
|
||||
assert(pa50[i][k] == pb50[i][k]);
|
||||
assert(pa50[i][k] == pc50[i][k]);
|
||||
assert(da50_4[i][k] == db50_4[i][k]);
|
||||
assert(da50_4[i][k] == dc50_4[i][k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_ab100();
|
||||
test_ab256();
|
||||
test_lab50();
|
||||
test_lab256();
|
||||
test_fab50();
|
||||
test_fab256();
|
||||
test_pab50();
|
||||
test_pab50_4();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <assert.h>
|
||||
|
||||
struct A
|
||||
{
|
||||
char x;
|
||||
unsigned y;
|
||||
long z;
|
||||
};
|
||||
|
||||
__striped A a[4];
|
||||
|
||||
__striped A c[4] = {
|
||||
{1, 1000, 100000},
|
||||
{2, 2000, 200000},
|
||||
{3, 3000, 300000},
|
||||
{4, 4000, 400000}
|
||||
};
|
||||
|
||||
__noinline long test_read(int k, char v)
|
||||
{
|
||||
A t = c[k];
|
||||
|
||||
if (t.x == v)
|
||||
return t.y;
|
||||
else
|
||||
return t.z;
|
||||
}
|
||||
|
||||
__noinline long test_write(int k, char v, long l)
|
||||
{
|
||||
A t = a[k];
|
||||
|
||||
if (t.x == v)
|
||||
t.y = l;
|
||||
else
|
||||
t.z = l;
|
||||
|
||||
return t.z;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
assert(test_read(0, 1) == 1000);
|
||||
assert(test_read(0, 0) == 100000);
|
||||
assert(test_read(2, 3) == 3000);
|
||||
assert(test_read(2, 0) == 300000);
|
||||
|
||||
for(char i=0; i<4; i++)
|
||||
a[i] = c[i];
|
||||
|
||||
assert(test_write(0, 1, 4711) == 100000);
|
||||
assert(test_write(0, 0, 4711) == 4711);
|
||||
assert(test_write(2, 3, 4711) == 300000);
|
||||
assert(test_write(2, 0, 4711) == 4711);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
char lstr[1025];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#if 1
|
||||
assert(strlen("") == 0);
|
||||
assert(strlen("1") == 1);
|
||||
assert(strlen("12") == 2);
|
||||
assert(strlen("123") == 3);
|
||||
assert(strlen("1234") == 4);
|
||||
assert(strlen("12345") == 5);
|
||||
assert(strlen("123456") == 6);
|
||||
#endif
|
||||
#if 1
|
||||
char * dp = lstr;
|
||||
for(int i=0; i<1024; i++)
|
||||
{
|
||||
*dp = 0;
|
||||
assert(strlen(lstr) == i);
|
||||
*dp++ = 'a';
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
void check_strtol(const char * str, char base, long val, char term)
|
||||
{
|
||||
char * t;
|
||||
assert(val == strtol(str, &t, base));
|
||||
assert(*t == term);
|
||||
}
|
||||
|
||||
void check_strtoul(const char * str, char base, unsigned long val, char term)
|
||||
{
|
||||
char * t;
|
||||
assert(val == strtoul(str, &t, base));
|
||||
assert(*t == term);
|
||||
}
|
||||
|
||||
void check_strtoi(const char * str, char base, int val, char term)
|
||||
{
|
||||
char * t;
|
||||
assert(val == strtoi(str, &t, base));
|
||||
assert(*t == term);
|
||||
}
|
||||
|
||||
void check_strtou(const char * str, char base, unsigned val, char term)
|
||||
{
|
||||
char * t;
|
||||
assert(val == strtou(str, &t, base));
|
||||
assert(*t == term);
|
||||
}
|
||||
|
||||
void check_strtof(const char * str, float val, char term)
|
||||
{
|
||||
char * t;
|
||||
assert(val == strtof(str, &t));
|
||||
assert(*t == term);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
check_strtol("123", 10, 123, '\0');
|
||||
check_strtol("123x", 10, 123, 'x');
|
||||
check_strtol(" 123x", 10, 123, 'x');
|
||||
check_strtol("-123x", 10, -123, 'x');
|
||||
|
||||
check_strtoul("123", 10, 123, '\0');
|
||||
check_strtoul("123x", 10, 123, 'x');
|
||||
check_strtoul(" 123x", 10, 123, 'x');
|
||||
|
||||
check_strtoi("123", 10, 123, '\0');
|
||||
check_strtoi("123x", 10, 123, 'x');
|
||||
check_strtoi(" 123x", 10, 123, 'x');
|
||||
check_strtoi("-123x", 10, -123, 'x');
|
||||
|
||||
check_strtou("123", 10, 123, '\0');
|
||||
check_strtou("123x", 10, 123, 'x');
|
||||
check_strtou(" 123x", 10, 123, 'x');
|
||||
check_strtof("123", 123, '\0');
|
||||
check_strtof("123x", 123, 'x');
|
||||
check_strtof(" 123x", 123, 'x');
|
||||
check_strtof("-123x", -123, 'x');
|
||||
check_strtof("123.5", 123.5, '\0');
|
||||
check_strtof("123.5x", 123.5, 'x');
|
||||
check_strtof(" 123.5x", 123.5, 'x');
|
||||
check_strtof("-123.5x", -123.5, 'x');
|
||||
check_strtof("123e2", 12300, '\0');
|
||||
check_strtof("123e2x", 12300, 'x');
|
||||
check_strtof(" 123e2x", 12300, 'x');
|
||||
check_strtof("-123e2x", -12300, 'x');
|
||||
check_strtof("123.5e2", 12350, '\0');
|
||||
check_strtof("123.5e2x", 12350, 'x');
|
||||
check_strtof(" 123.5e2x", 12350, 'x');
|
||||
check_strtof("-123.5e2x", -12350, 'x');
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char teststr[2000], substr[200];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Test strstr with basic functionality
|
||||
assert(strcmp(strstr("hello world", "hello"), "hello world") == 0);
|
||||
assert(strcmp(strstr("hello world", "world"), "world") == 0);
|
||||
assert(strcmp(strstr("hello world", "lo wo"), "lo world") == 0);
|
||||
assert(strstr("hello world", "xyz") == nullptr);
|
||||
|
||||
// Test strstr with empty substring
|
||||
assert(strcmp(strstr("hello", ""), "hello") == 0); // empty substring matches at start
|
||||
assert(strcmp(strstr("", ""), "") == 0);
|
||||
|
||||
// Test strstr with substring not found
|
||||
assert(strstr("hello", "world") == nullptr);
|
||||
assert(strstr("abc", "xyz") == nullptr);
|
||||
assert(strstr("short", "longer") == nullptr);
|
||||
|
||||
// Test strstr with single character substring
|
||||
assert(strcmp(strstr("hello", "h"), "hello") == 0);
|
||||
assert(strcmp(strstr("hello", "e"), "ello") == 0);
|
||||
assert(strcmp(strstr("hello", "o"), "o") == 0);
|
||||
assert(strstr("hello", "x") == nullptr);
|
||||
|
||||
// Test strstr with substring at different positions
|
||||
assert(strcmp(strstr("abcdefgh", "abc"), "abcdefgh") == 0); // at start
|
||||
assert(strcmp(strstr("abcdefgh", "def"), "defgh") == 0); // in middle
|
||||
assert(strcmp(strstr("abcdefgh", "fgh"), "fgh") == 0); // at end
|
||||
|
||||
// Test strstr with repeated patterns
|
||||
assert(strcmp(strstr("ababab", "ab"), "ababab") == 0); // finds first occurrence
|
||||
assert(strcmp(strstr("ababab", "ba"), "babab") == 0);
|
||||
assert(strcmp(strstr("ababab", "bab"), "babab") == 0);
|
||||
|
||||
// Test strstr with overlapping patterns
|
||||
assert(strcmp(strstr("aaaa", "aa"), "aaaa") == 0); // finds first match
|
||||
assert(strcmp(strstr("ababa", "aba"), "ababa") == 0);
|
||||
|
||||
// Test strstr where substring equals the string
|
||||
assert(strcmp(strstr("test", "test"), "test") == 0);
|
||||
assert(strcmp(strstr("a", "a"), "a") == 0);
|
||||
|
||||
// Test strstr with special characters
|
||||
assert(strcmp(strstr("hello, world!", "o, w"), "o, world!") == 0);
|
||||
assert(strcmp(strstr("a.b.c.d", ".b."), ".b.c.d") == 0);
|
||||
assert(strcmp(strstr("x y z", " y "), " y z") == 0);
|
||||
|
||||
// Build a long test string with pattern
|
||||
for(int i = 0; i < 1900; i++)
|
||||
{
|
||||
teststr[i] = 'a' + (i & 7);
|
||||
}
|
||||
teststr[1900] = '\0';
|
||||
|
||||
// Test strstr with long strings
|
||||
strcpy(substr, "abcdefgh");
|
||||
char *result = strstr(teststr, substr);
|
||||
assert(result == teststr); // pattern starts at beginning
|
||||
assert(strncmp(result, substr, 8) == 0);
|
||||
|
||||
// Test strstr with pattern that appears later
|
||||
strcpy(substr, "bcdefgha");
|
||||
result = strstr(teststr, substr);
|
||||
assert(result == teststr + 1); // pattern starts at position 1
|
||||
assert(strncmp(result, substr, 8) == 0);
|
||||
|
||||
// Test strstr with pattern not in string
|
||||
strcpy(substr, "zzzzz");
|
||||
assert(strstr(teststr, substr) == nullptr);
|
||||
|
||||
// Test strstr with longer substring than string
|
||||
strcpy(teststr, "short");
|
||||
strcpy(substr, "this is longer");
|
||||
assert(strstr(teststr, substr) == nullptr);
|
||||
|
||||
// Test strstr with case sensitivity
|
||||
assert(strstr("Hello", "hello") == nullptr); // case sensitive
|
||||
assert(strcmp(strstr("Hello", "Hello"), "Hello") == 0);
|
||||
|
||||
// Test strstr with partial matches that fail
|
||||
assert(strstr("abcde", "abcx") == nullptr);
|
||||
assert(strstr("testing", "tester") == nullptr);
|
||||
|
||||
// Test strstr with multiple occurrences (finds first)
|
||||
strcpy(teststr, "the quick brown fox jumps over the lazy dog");
|
||||
assert(strcmp(strstr(teststr, "the"), "the quick brown fox jumps over the lazy dog") == 0);
|
||||
assert(strcmp(strstr(teststr, "o"), "own fox jumps over the lazy dog") == 0); // first 'o'
|
||||
|
||||
// Test strstr with whole word searches
|
||||
assert(strcmp(strstr(teststr, "quick"), "quick brown fox jumps over the lazy dog") == 0);
|
||||
assert(strcmp(strstr(teststr, "fox"), "fox jumps over the lazy dog") == 0);
|
||||
assert(strcmp(strstr(teststr, "dog"), "dog") == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
|
||||
|
||||
struct Point
|
||||
{
|
||||
int x, y;
|
||||
};
|
||||
|
||||
|
||||
Point tcorners[8], pcorners[8];
|
||||
|
||||
int bm_line(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void drawCube(void)
|
||||
{
|
||||
for(char i=0; i<8; i++)
|
||||
{
|
||||
if (!(i & 1))
|
||||
bm_line();
|
||||
if (!(i & 2))
|
||||
bm_line();
|
||||
if (!(i & 4))
|
||||
bm_line();
|
||||
|
||||
pcorners[i] = tcorners[i];
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for(int i=0; i<8; i++)
|
||||
{
|
||||
tcorners[i].x = (i + 1) * 3;
|
||||
tcorners[i].y = (i + 1) * 7;
|
||||
}
|
||||
|
||||
drawCube();
|
||||
|
||||
int sum = 0;
|
||||
for(int i=0; i<8; i++)
|
||||
{
|
||||
sum += pcorners[i].x;
|
||||
sum -= tcorners[i].y;
|
||||
}
|
||||
|
||||
return sum + 144;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user