Skip to content

Commit

Permalink
Merge pull request #10 from wilsonk/update_tests1
Browse files Browse the repository at this point in the history
Update tests
  • Loading branch information
Syniurge committed Apr 17, 2015
2 parents 880818e + 1b5d2ff commit 132ecf8
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 18 deletions.
21 changes: 13 additions & 8 deletions tests/calypso/libstdc++/deque/deque.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ void main()
auto dq2 = new deque!(int)(dq);
auto dq3 = new deque!(double)(10);
auto dq4 = new deque!(int);
auto dq5 = new deque!(int);

// Fill deque with 10 ints
writeln("push_back 10 ints onto dq");
for (int i = 0; i < 10; i++)
{
dq.push_back(i);
dq5.push_back(i);
}

// Print out
Expand Down Expand Up @@ -80,24 +82,27 @@ void main()
writeln("dq3 is empty = " ~ (dq3.empty() ? "Yes" : "No"));
writeln("dq3 size = ", dq3.size());

dq.assign(10,5);
auto it = new deque!(int).iterator;

// FAILURES

// Assertion `int_regs + sse_regs <= 2' failed !?!?!?
//it = dq5.begin();
// Idiomatic C++ iterator usage doesn't work yet. See list.d also
//for (int i=0; i < dq.size(); it++, i++)
//writeln(*it);

// 'no property popFront' here
//foreach(deq; dq3) {}

//auto second = new deque!(int)(4, 100);

//dq.assign(10,5);

// Doesn't seem to be picking up all template decls
//immutable int xx = 9;
//immutable float yy = 8.1;
//auto dq5 = new deque!(xx, yy);

// 'no property begin' - almost seems like multipe args messes
// up the function lookups because .at(int), etc. work?
//auto it = dq.begin();

// 'no property insert'
//dq.insert(it, 2, 20);
// deque iterators need to work for this to work
// dq.insert(it, 2, 20);
}
66 changes: 57 additions & 9 deletions tests/calypso/libstdc++/list/list.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ modmap (C++) "<list>";
import std.stdio, std.conv, std.string;
import (C++) std.list;

bool single_digit (const int value) { return (value<10); }

struct is_odd {
bool opCall (const int value) { return (value%2)==1; }
};

void main()
{
auto l = new list!int;
//auto l1 = new list!(4, 100); // FAILURE
//auto l2 = new list!(l); // FAILURE
auto l2 = new list!(int)(l);
auto l3 = new list!int;
auto l4 = new list!int;

immutable int x = 11;
immutable int y = 4;
Expand All @@ -29,11 +37,51 @@ void main()
l.sort();
writeln("List front after sort is ", l.front());

/* FAILURE -- Iterators don't work yet
auto j = l.begin();
for (int i = 0; i < l.size(); i++)
{
writeln(j++);
}
*/
}
// FAILURE: the next line causes k++ to fail if the iterator
// isn't explicitly initialized like below!
// auto k = l.begin();

auto k = new list!(int).iterator;

// for(; k != l.end(); k++)
// FAILURE: classes.cpp:256: DValue* DtoCastClass(Loc&,
// DValue*, Type*): Assertion `to->ty == Tclass' failed


writeln("\nList:");
// So we have to use this more laboured method below for now
k = l.begin;
for (int i=0; i < l.size() ; k++, i++)
writeln(*k);

writeln("\nList2 after swapping in List:");
// swap works
l2.swap(l);
k = l2.begin;
for (int i=0; i < l2.size() ; k++, i++)
writeln(*k);

l3.assign(l2.begin(), l2.end());

writeln("\nList4 after assign from array:");
auto arr = [7, 64, 9, 22, 4];
l4.assign(arr.ptr, arr.ptr+5);
k = l4.begin;
for (int i=0; i < l4.size() ; k++, i++)
writeln(*k);


writeln("\nList4 after single_digits removed:");
bool function(const int) sd = &single_digit;
l4.remove_if(sd);
k = l4.begin;
for (int i=0; i < l4.size() ; k++, i++)
writeln(*k);

// FAILURE: unhandled D->C++ conversion
/*is_odd io;
bool delegate(const int) iof;
iof = &io.opCall;
l4.remove_if(iof);*/

}
12 changes: 12 additions & 0 deletions tests/calypso/libstdc++/stack/stack.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,22 @@ import (C++) std.deque;
void main()
{
auto dq = new deque!(int);
for (int i = 0;i<10; i++)
dq.push_back(i);

//auto v = new vector!(int)(2,200); //FAILURE

auto st1 = new stack!char;
auto dq2 = new stack!(int)(dq);
//auto st2 = new stack!(int, vector!int); //FAILURE

writeln("stack appears to work");
writeln("empty stack size = ", st1.size());
writeln("10 element deque stack size = ", dq2.size());

for (int i = 0;i<10; i++)
{
writeln("popping the top of a stack of 10 elements from ordered deque = ", dq2.top());
dq2.pop();
}
}
36 changes: 35 additions & 1 deletion tests/calypso/libstdc++/vector/vector.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (C++) std.vector;
void main()
{
auto v = new vector!char;
auto v1 = new vector!char;

v.reserve(10);
writeln("vector reserved with size of: ", v.capacity());

foreach (c; "Europa")
v.push_back(c);
Expand All @@ -26,5 +28,37 @@ void main()
for (int i = 0; i < v.size(); i++)
reconstruct ~= to!string(v.at(i));

write("printing vector with writeln: ");
writeln(reconstruct);
}

writeln("vector length is: ", v.size());
v.resize(5);
writeln("vector length after resize(5): ", v.size());

writeln("vector capacity = ", v.capacity());

write("printing vector with iterator: ");
auto it = new vector!(char).iterator;
it = v.begin();
// Idiomatic C++ iterator use isn't working yet...see list.d also
for (int i = 0; i < v.size(); it++, i++)
write(*it);
writeln(*it);


writeln("writing second vector with iterator: ");
auto arr = "567";
v1.assign(arr.ptr, arr.ptr+3);
it = v1.begin;
for (int i = 0; i < v.size(); it++, i++)
write(*it);
writeln(*it);

// FAILURE
// classes.cpp:256: DValue* DtoCastClass(Loc&, DValue*, Type*):
// Assertion `to->ty == Tclass' failed.
//const char x = '5';
//write("inserting character into first vector: ");
//it = v.begin();
//v.insert(it, x);
}

0 comments on commit 132ecf8

Please sign in to comment.