Added tools/tests/

actorid
Nicolay Korslund 15 years ago
parent f526cc640b
commit abde68fed6

@ -33,9 +33,20 @@ struct SliceArray
const T* ptr;
size_t length;
/// Initialize to zero length
SliceArray() : ptr(0), length(0) {}
/// Initialize from pointer + length
SliceArray(const T* _ptr, size_t _length)
: ptr(_ptr), length(_length) {}
/// Initialize from null-terminated string
SliceArray(const char* str)
{
ptr = str;
length = strlen(str);
}
bool operator==(SliceArray &t)
{
return
@ -52,8 +63,7 @@ struct SliceArray
}
/** This allocates a copy of the data. Only use this for debugging
and error messages.
*/
and error messages. */
std::string toString()
{ return std::string(ptr,length); }
};

@ -0,0 +1 @@
*_test

@ -0,0 +1,12 @@
GCC=g++
all: strops_test slice_test
slice_test: slice_test.cpp ../slice_array.h
$(GCC) $< -o $@
strops_test: strops_test.cpp ../stringops.h ../stringops.cpp
$(GCC) $< -o $@ ../stringops.cpp
clean:
rm *_test

@ -0,0 +1,6 @@
hello, len=5
001
hell, len=4
010
01
4 3

@ -0,0 +1,30 @@
#include <iostream>
using namespace std;
#include <assert.h>
#include "../slice_array.h"
int main()
{
SString s, t;
s = SString("hello");
cout << s.toString() << ", len=" << s.length << endl;
cout << (s=="hel") << (s=="hell") << (s=="hello") << endl;
t = s;
s = SString("othello"+2, 4);
cout << s.toString() << ", len=" << s.length << endl;
cout << (s=="hel") << (s=="hell") << (s=="hello") << endl;
cout << (s==t) << (SString("hello")==t) << endl;
const int arr[4] = {1,2,3,4};
IntArray ia(arr,4);
cout << ia.length << " " << ia.ptr[2] << endl;
return 0;
}

@ -0,0 +1,18 @@
#include <assert.h>
#include "../stringops.h"
int main()
{
assert(begins("abc", "a"));
assert(begins("abc", "ab"));
assert(begins("abc", "abc"));
assert(begins("abcd", "abc"));
assert(!begins("abc", "b"));
assert(!begins("abc", "bc"));
assert(!begins("abc", "bcd"));
assert(!begins("abc", "abcd"));
return 0;
}

@ -0,0 +1,18 @@
#!/bin/bash
make || exit
mkdir -p output
PROGS=*_test
for a in $PROGS; do
if [ -f "output/$a.out" ]; then
echo "Running $a:"
$a | diff output/$a.out -
else
echo "Creating $a.out"
$a > "output/$a.out"
git add "output/$a.out"
fi
done
Loading…
Cancel
Save