Skip to content

Instantly share code, notes, and snippets.

@track3r
Created December 21, 2017 09:29
Show Gist options
  • Save track3r/dc0d0c1d78dfa63a552b81e1c2f435c2 to your computer and use it in GitHub Desktop.
Save track3r/dc0d0c1d78dfa63a552b81e1c2f435c2 to your computer and use it in GitHub Desktop.
Object hash bug
import haxe.ds.ObjectMap;
class ComponentA
{
public var a: Int;
}
class ComponentB
{
public var a: Int;
public var b: Int;
}
class ComponentC
{
public var a: Int;
public var b: Int;
public var c: Int;
}
class ComponentD
{
public var a: Int;
public var b: Int;
public var c: Int;
public var d: Int;
}
class ComponentE
{
public var a: Int;
public var b: Int;
public var c: Int;
public var d: Int;
public var e: Int;
}
class Test
{
static var errors = new Array<String>();
static var lastErrorCount = 0;
var x:Int;
public function new()
{
x = 1;
}
public static function log(t:String)
{
Sys.println(t);
}
public static function v(t:String)
{
Sys.println(" " + t);
}
public static function ok()
{
if (lastErrorCount==errors.length)
{
v("ok");
return 0;
}
else
{
lastErrorCount=errors.length;
v("bad");
return 1;
}
}
public static function error(e:String)
{
Sys.println("Test Failed:" + e);
errors.push(e);
return -1;
}
public static function makeGarbage(): String
{
var ret = "";
for (i in 0 ... 800)
{
var str = "fsadsadasdasdas" + '${i*2}';
var str2 = str + "dsal;dksal;dkl;kasldasda" + '${i*3}';
var str3 = str + str2 + "409023482390849023" + '${i*4}';
var str4 = str + str2 + str3 + "fdsfkdsl;fkdsl;fds" + '${i*5}';
ret = ret + str4;
}
return ret;
}
public static function main()
{
var exitCode = 0;
//exitCode |= testDynamicMember();
var map = new ObjectMap<Dynamic,String>();
map.set(ComponentA, "a");
map.set(ComponentB, "b");
map.set(ComponentC, "c");
map.set(ComponentD, "a");
map.set(ComponentE, "a");
var str = makeGarbage();
//while(true)
{
}
for (cls in map.keys())
{
trace('$cls');
if (!map.exists(cls))
{
trace('map is broken');
exitCode = -1;
}
}
if (exitCode!=0)
Sys.println("############# Errors running tests:\n " + errors.join("\n ") );
else
Sys.println("All tests passed.");
Sys.exit(exitCode);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment