Menu
Home
Create new Paste
Log in
Code
Theme: cobalt
Theme: eclipse
Theme: elegant
Theme: monokai
Theme: neat
Theme: night
Theme: rubyblue
static void main(){} class Num { int a; } unittest { Num[] nums = new Num[10]; alias void delegate() Func; Func[] funcs = new Func[10]; for (int i = 0; i < 10; ++i) { Num num = nums[i] = new Num(); funcs[i] = {num.a = i;}; } foreach(num; nums) { assert(num.a == 0); // All objects has their default value. } foreach(func; funcs) { func(); // We call the anonymous functions which should change the value of objects. } assert(nums[9].a == 10); // TRUE! It is the only elem what changes foreach(i, num; nums) { assert(num.a == i); // But they don't, The first round passes (0==0), but the second round (0 == 1) fails. } }
Result:
Runtime error
/
Return code: 1 (Hangup)
/
Compilation time:
0.145
seconds
/
Run time:
0.001
seconds
Application error:
core.exception.AssertError@c730(23): unittest failure
----------------
Sharp
@
03-10-2012 15:48:02
wrote:
Username
Message
Add comment
Paste info
Author:
Guest
Views:
123
Private:
no
Expires:
Never
Uploaded:
03.10.12 15:47
Votes
:
0
Tweet
Compilation
Compiler:
DMD 2.060
Pointer size:
m64
Actions
Download
Fork
Raw
×
Confirm
Are you sure you want to delete this paste?
There's no way back!
×
Confirm
Reason