add some tiled properties test

This commit is contained in:
2016-02-02 02:05:09 +06:00
parent 1920b49e47
commit 17c5ce898e
5 changed files with 137 additions and 1 deletions

View File

@@ -48,6 +48,7 @@
<Compile Include="Assets\IsoTools\Scripts\Internal\Editor\IsoObjectEditor.cs" /> <Compile Include="Assets\IsoTools\Scripts\Internal\Editor\IsoObjectEditor.cs" />
<Compile Include="Assets\IsoTools\Tiled\Internal\Editor\TiledMapAssetEditor.cs" /> <Compile Include="Assets\IsoTools\Tiled\Internal\Editor\TiledMapAssetEditor.cs" />
<Compile Include="Assets\IsoTools\Tiled\Internal\Editor\TiledMapPostprocessor.cs" /> <Compile Include="Assets\IsoTools\Tiled\Internal\Editor\TiledMapPostprocessor.cs" />
<Compile Include="Assets\IsoTools\Tiled\Internal\Editor\TiledMapPropertiesTests.cs" />
<Reference Include="UnityEditor.Advertisements"> <Reference Include="UnityEditor.Advertisements">
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/Advertisements/Editor/UnityEditor.Advertisements.dll</HintPath> <HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/Advertisements/Editor/UnityEditor.Advertisements.dll</HintPath>
</Reference> </Reference>

View File

@@ -0,0 +1,115 @@
using UnityEngine;
using NUnit.Framework;
using System.Collections.Generic;
namespace IsoTools.Tiled.Internal {
public class TiledMapPropertiesTests {
[Test]
public void Test00() {
var props = new TiledMapProperties(null);
Assert.AreEqual(props.Count, 0);
Assert.False(props.Has(""));
Assert.False(props.Has(string.Empty));
Assert.False(props.Has("prop1"));
}
[Test]
public void Test01() {
var prop_list = new List<string>{
"prop1", "val1",
"prop2", "val2",
"prop3", "val3",
"fakep"
};
var props = new TiledMapProperties(prop_list);
Assert.AreEqual(props.Count, 3);
Assert.True(props.Has("prop1"));
Assert.True(props.Has("prop2"));
Assert.True(props.Has("prop3"));
Assert.False(props.Has(""));
Assert.False(props.Has("val2"));
Assert.False(props.Has("prop4"));
Assert.False(props.Has(string.Empty));
}
[Test]
public void Test02() {
var props = new TiledMapProperties(null);
Assert.Throws<UnityException>(() => { props.GetAsBool (""); });
Assert.Throws<UnityException>(() => { props.GetAsShort (""); });
Assert.Throws<UnityException>(() => { props.GetAsInt (""); });
Assert.Throws<UnityException>(() => { props.GetAsLong (""); });
Assert.Throws<UnityException>(() => { props.GetAsFloat (""); });
Assert.Throws<UnityException>(() => { props.GetAsDouble(""); });
Assert.Throws<UnityException>(() => { props.GetAsString(""); });
}
[Test]
public void Test03() {
var props = new TiledMapProperties(null);
bool v0;
short v1;
int v2;
long v3;
float v4;
double v5;
string v6;
Assert.False(props.TryGetAsBool ("", out v0));
Assert.False(props.TryGetAsShort ("", out v1));
Assert.False(props.TryGetAsInt ("", out v2));
Assert.False(props.TryGetAsLong ("", out v3));
Assert.False(props.TryGetAsFloat ("", out v4));
Assert.False(props.TryGetAsDouble("", out v5));
Assert.False(props.TryGetAsString("", out v6));
}
[Test]
public void Test04() {
var prop_list = new List<string>{
"bool" , "true",
"short" , "64",
"int" , "128",
"long" , "1024",
"float" , "1.2",
"double", "1.23",
"string", "hello"
};
var props = new TiledMapProperties(prop_list);
bool v0;
short v1;
int v2;
long v3;
float v4;
double v5;
string v6;
Assert.True(props.TryGetAsBool ("bool" , out v0));
Assert.True(props.TryGetAsShort ("short" , out v1));
Assert.True(props.TryGetAsInt ("int" , out v2));
Assert.True(props.TryGetAsLong ("long" , out v3));
Assert.True(props.TryGetAsFloat ("float" , out v4));
Assert.True(props.TryGetAsDouble("double", out v5));
Assert.True(props.TryGetAsString("string", out v6));
Assert.AreEqual(v0, true);
Assert.AreEqual(v1, 64);
Assert.AreEqual(v2, 128);
Assert.AreEqual(v3, 1024);
Assert.AreEqual(v4, 1.2f);
Assert.AreEqual(v5, 1.23);
Assert.AreEqual(v6, "hello");
Assert.AreEqual(props.GetAsBool ("bool" ), v0);
Assert.AreEqual(props.GetAsShort ("short" ), v1);
Assert.AreEqual(props.GetAsInt ("int" ), v2);
Assert.AreEqual(props.GetAsLong ("long" ), v3);
Assert.AreEqual(props.GetAsFloat ("float" ), v4);
Assert.AreEqual(props.GetAsDouble("double"), v5);
Assert.AreEqual(props.GetAsString("string"), v6);
}
}
} // namespace IsoTools.Tiled.Internal

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1fe9dff9033b94dc2bcc389ef678be7b
timeCreated: 1454350914
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -46,4 +46,4 @@ namespace IsoTools.Tiled {
public class TiledMapAsset : ScriptableObject { public class TiledMapAsset : ScriptableObject {
public TiledMapData Data = new TiledMapData(); public TiledMapData Data = new TiledMapData();
} }
} // namespace IsoTools.Tiled } // namespace IsoTools.Tiled

View File

@@ -14,6 +14,14 @@ namespace IsoTools.Tiled {
_properties = properties; _properties = properties;
} }
public int Count {
get {
return _properties != null
? _properties.Count / 2
: 0;
}
}
public bool Has(string property_name) { public bool Has(string property_name) {
if ( _properties != null ) { if ( _properties != null ) {
for ( var i = 0; i < _properties.Count / 2; ++i ) { for ( var i = 0; i < _properties.Count / 2; ++i ) {