Bug 14082 – RedBlackTree unittest fails with custom predicate less

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-01-30T13:42:00Z
Last change time
2015-02-18T03:41:42Z
Assigned to
schveiguy
Creator
drug2004

Comments

Comment #0 by drug2004 — 2015-01-30T13:42:36Z
import std.container: RedBlackTree; class Test(T, alias less = "a<b") { alias Container = RedBlackTree!(T, less); } unittest { alias Foo = Test!(int); } void main() {} run using rdmd -unittest filename.d this code causes unittest failure: std/container/rbtree.d Lines 846-850: static if(less == "a < b") auto vals = [1, 2, 3, 4, 5]; else auto vals = [5, 4, 3, 2, 1]; assert(equal(r, vals)); because less is set to "a<b" instead of "a < b" by default, i.e. spaces have meaning here. What is the best way to fix that?
Comment #1 by schveiguy — 2015-01-30T14:17:27Z
The real answer is that phobos unit tests should not run when you run your private unit tests. That is really a language change that needs to happen. The band-aid answer is that the unit tests should ONLY run if we know exactly the instantiating parameters are. When I wrote those, I didn't consider that I should worry about the less parameter.
Comment #2 by drug2004 — 2015-01-30T14:37:17Z
I agree. Also I'm curious why RedBlackTree instance in Phobos unittest get less from my private unittest?
Comment #3 by schveiguy — 2015-01-30T14:49:49Z
(In reply to drug007 from comment #2) > I agree. Also I'm curious why RedBlackTree instance in Phobos unittest get > less from my private unittest? RedBlackTree unit tests are done inside the class, so every instantiation of RBT creates its own set of unit tests. It's actually quite useful, I found about 3 compiler bugs because of it. But the drawback is that EVERY instantiation of RBT creates its own unit tests. And it's nearly impossible to make a unit test that works for every instantation. So I have code that limits when unit tests run, based on the *type* of the data stored. But I never thought of limiting it based on the lambda. I just have to add a few static ifs, and you will be all set.
Comment #4 by drug2004 — 2015-01-30T14:58:22Z
I see. Thanks for clarification!
Comment #5 by schveiguy — 2015-01-30T15:36:16Z
Comment #6 by github-bugzilla — 2015-01-30T16:30:25Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/acac6266085454224b144316b088f62fc96d95b5 Fix issue 14082 -- unit test should only test known cases in red black tree. https://github.com/D-Programming-Language/phobos/commit/a4bd3dff631372062d192a7295eff3401098b7f5 Merge pull request #2936 from schveiguy/issue14082 Fix issue 14082 -- RedBlackTree unittest fails with custom predicate less
Comment #7 by github-bugzilla — 2015-02-18T03:41:42Z