From 84e3cba1bc033b4887af5c45ec9f9b7aafdb71e2 Mon Sep 17 00:00:00 2001 From: Malachi Griffie Date: Tue, 4 Mar 2014 16:49:09 -0800 Subject: [PATCH] Added an Enum to mock objects used for serialization tests --- test/src/mock/MockEnum.as | 22 ++++++++++++++++++- test/src/mock/foo/bar/BaseClass.as | 2 ++ .../mock/foo/bar/CustomSerializationClass.as | 10 ++++++--- test/src/mock/foo/bar/DynamicBaseClass.as | 2 ++ test/src/mock/foo/bar/_BaseClassContent.as | 5 +++++ test/src/test/nexus/math/AbstractIPRNGTest.as | 6 ++--- .../serialization/json/JsonSerializerTest.as | 4 +++- 7 files changed, 43 insertions(+), 8 deletions(-) diff --git a/test/src/mock/MockEnum.as b/test/src/mock/MockEnum.as index 325894e..9431976 100644 --- a/test/src/mock/MockEnum.as +++ b/test/src/mock/MockEnum.as @@ -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(); @@ -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; + } } } \ No newline at end of file diff --git a/test/src/mock/foo/bar/BaseClass.as b/test/src/mock/foo/bar/BaseClass.as index cd32a0e..16caf7e 100644 --- a/test/src/mock/foo/bar/BaseClass.as +++ b/test/src/mock/foo/bar/BaseClass.as @@ -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")] diff --git a/test/src/mock/foo/bar/CustomSerializationClass.as b/test/src/mock/foo/bar/CustomSerializationClass.as index ab27355..cf0c926 100644 --- a/test/src/mock/foo/bar/CustomSerializationClass.as +++ b/test/src/mock/foo/bar/CustomSerializationClass.as @@ -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() { @@ -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; } diff --git a/test/src/mock/foo/bar/DynamicBaseClass.as b/test/src/mock/foo/bar/DynamicBaseClass.as index e71df0d..7c80cc2 100644 --- a/test/src/mock/foo/bar/DynamicBaseClass.as +++ b/test/src/mock/foo/bar/DynamicBaseClass.as @@ -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")] diff --git a/test/src/mock/foo/bar/_BaseClassContent.as b/test/src/mock/foo/bar/_BaseClassContent.as index 9b16930..81823b7 100644 --- a/test/src/mock/foo/bar/_BaseClassContent.as +++ b/test/src/mock/foo/bar/_BaseClassContent.as @@ -1,3 +1,4 @@ + private var m_baseString : String; private var m_baseVector : Vector.; private var m_subObj1 : SubObject; @@ -5,6 +6,7 @@ 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 @@ -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; } diff --git a/test/src/test/nexus/math/AbstractIPRNGTest.as b/test/src/test/nexus/math/AbstractIPRNGTest.as index 432af87..3165327 100644 --- a/test/src/test/nexus/math/AbstractIPRNGTest.as +++ b/test/src/test/nexus/math/AbstractIPRNGTest.as @@ -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); } @@ -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); } @@ -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); } diff --git a/test/src/test/nexus/utils/serialization/json/JsonSerializerTest.as b/test/src/test/nexus/utils/serialization/json/JsonSerializerTest.as index 98b41bc..32eeb45 100644 --- a/test/src/test/nexus/utils/serialization/json/JsonSerializerTest.as +++ b/test/src/test/nexus/utils/serialization/json/JsonSerializerTest.as @@ -1,5 +1,5 @@ // Copyright 2011 Malachi Griffie -// +// // 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/. @@ -7,6 +7,7 @@ package test.nexus.utils.serialization.json { import asunit.framework.TestCase; +import mock.MockEnum; import mock.testing_namespace; import nexus.utils.ObjectUtils; @@ -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();