Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Added an Enum to mock objects used for serialization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Malachi Griffie committed Mar 5, 2014
1 parent be02fae commit 84e3cba
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 8 deletions.
22 changes: 21 additions & 1 deletion test/src/mock/MockEnum.as
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ package mock
{

import nexus.*;
import nexus.utils.serialization.json.IJsonSerializable;

public class MockEnum extends Enum
public class MockEnum extends Enum implements IJsonSerializable
{
public static const Value1 : MockEnum = new MockEnum();
public static const Value2 : MockEnum = new MockEnum();
Expand All @@ -19,6 +20,25 @@ public class MockEnum extends Enum
public static const FOO:String = "FOO";

public static function get All():EnumSet { return Enum.values(MockEnum); }

/* INTERFACE nexus.utils.serialization.json.IJsonSerializable */

public function toJSON(key:String):Object
{
return this.name;
}

public function jsonLikeType(data:Object):Boolean
{
var str : String = data + "";
return false;
}

public static function fromNative(data:Object):MockEnum
{
var enum : Object = Enum.fromString(MockEnum, data +"");
return enum as MockEnum;
}
}

}
2 changes: 2 additions & 0 deletions test/src/mock/foo/bar/BaseClass.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package mock.foo.bar
{

import mock.foo.SubObject;
import mock.MockEnum;
import mock.testing_namespace;
import nexus.Enum;
import nexus.errors.NotImplementedError;

[ClassMetadata(on="BaseClass")]
Expand Down
10 changes: 7 additions & 3 deletions test/src/mock/foo/bar/CustomSerializationClass.as
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import nexus.utils.serialization.json.IJsonSerializable;

public class CustomSerializationClass extends BaseClass implements IJsonSerializable
{
private static var s_id : int = 1;
static public function get id():int { return s_id; }
private static var s_id:int = 1;

static public function get id():int
{
return s_id;
}

public function CustomSerializationClass()
{
Expand All @@ -25,7 +29,7 @@ public class CustomSerializationClass extends BaseClass implements IJsonSerializ

public static function fromNative(data:Object):Object
{
var result : CustomSerializationClass = new CustomSerializationClass();
var result:CustomSerializationClass = new CustomSerializationClass();
result.baseString = data + "";
return result;
}
Expand Down
2 changes: 2 additions & 0 deletions test/src/mock/foo/bar/DynamicBaseClass.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package mock.foo.bar
{

import mock.foo.SubObject;
import mock.MockEnum;
import mock.testing_namespace;
import nexus.Enum;
import nexus.errors.NotImplementedError;

[ClassMetadata(on="DynamicBaseClass")]
Expand Down
5 changes: 5 additions & 0 deletions test/src/mock/foo/bar/_BaseClassContent.as
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

private var m_baseString : String;
private var m_baseVector : Vector.<String>;
private var m_subObj1 : SubObject;
private var m_subObj2 : SubObject;

public var baseVar : int;
testing_namespace var baseVar : String = "";
private var m_enum : MockEnum;

[MethodMetadata(on="BaseClass")]
public function baseMethod(arg1:String, arg2:String="", arg3:Array=null):Object
Expand All @@ -22,6 +24,9 @@ public function set subObj1(value:SubObject):void
m_subObj1 = value;
}

public function get mockEnum():MockEnum { return m_enum; }
public function set mockEnum(value:MockEnum):void { m_enum = value; }

[PropertyMetadata(on="BaseClass")]
public function get subObj2():SubObject { return m_subObj2; }

Expand Down
6 changes: 3 additions & 3 deletions test/src/test/nexus/math/AbstractIPRNGTest.as
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class AbstractIPRNGTest extends TestCase
m_generator.next();
}
var end:int = getTimer() - start;
trace("test_performance", m_generator, STRESS_ITERATIONS + " iterations: " + end + "ms");
//trace("test_performance", m_generator, STRESS_ITERATIONS + " iterations: " + end + "ms");
assertTrue(end < 800);
}

Expand Down Expand Up @@ -194,7 +194,7 @@ public class AbstractIPRNGTest extends TestCase
}
var diff : int = Math.abs(trueCount - falseCount);
//trace("test_boolean", m_generator, diff, trueCount, falseCount, diff / DISTRIBUTION_ITERATIONS * 100);
trace("test_boolean", m_generator, "variance", diff / DISTRIBUTION_ITERATIONS);
//trace("test_boolean", m_generator, "variance", diff / DISTRIBUTION_ITERATIONS);
assertTrue(diff / DISTRIBUTION_ITERATIONS < .02);
}

Expand All @@ -219,7 +219,7 @@ public class AbstractIPRNGTest extends TestCase
}
var diff : int = Math.abs(upCount - downCount);
//trace("test_round", m_generator, diff, upCount, downCount, diff / DISTRIBUTION_ITERATIONS * 100);
trace("test_round", m_generator, "variance", diff / DISTRIBUTION_ITERATIONS);
//trace("test_round", m_generator, "variance", diff / DISTRIBUTION_ITERATIONS);
assertTrue("Variance > .02 => " + (diff / DISTRIBUTION_ITERATIONS), diff / DISTRIBUTION_ITERATIONS < .02);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright 2011 Malachi Griffie <[email protected]>
//
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package test.nexus.utils.serialization.json
{

import asunit.framework.TestCase;
import mock.MockEnum;
import mock.testing_namespace;
import nexus.utils.ObjectUtils;

Expand Down Expand Up @@ -56,6 +57,7 @@ public class JsonSerializerTest extends TestCase
m_base1 = new BaseClass();
m_base2 = new BaseClass();
m_base1.baseVar = m_base2.baseVar = 100;
m_base1.mockEnum = m_base2.mockEnum = MockEnum.Value2;
m_base1.testing_namespace::baseVar = "test_serialization3";

m_serializer1 = new JsonSerializer();
Expand Down

0 comments on commit 84e3cba

Please sign in to comment.