Browse Source
- Uses XorShift style bit mixing on hashes to avoid collisions when input and section are identical - Added tests to verify basic text variation is working as required.master
desktop-maesty/steve
6 years ago
4 changed files with 146 additions and 1 deletions
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: b0ab687196033764d88aa5c2e32c035b |
||||
folderAsset: yes |
||||
DefaultImporter: |
||||
externalObjects: {} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,114 @@
|
||||
using UnityEngine; |
||||
using UnityEngine.TestTools; |
||||
using NUnit.Framework; |
||||
using System.Collections; |
||||
|
||||
public class FungusTextVariationSelectionTests |
||||
{ |
||||
[Test] |
||||
public void SimpleSequenceSelection() |
||||
{ |
||||
Fungus.TextVariationHandler.ClearHistory(); |
||||
|
||||
string startingText = @"This is test [a|b|c]"; |
||||
string startingTextA = @"This is test a"; |
||||
string startingTextB = @"This is test b"; |
||||
string startingTextC = @"This is test c"; |
||||
|
||||
string res = string.Empty; |
||||
|
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextA); |
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextB); |
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextC); |
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextC); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleCycleSelection() |
||||
{ |
||||
Fungus.TextVariationHandler.ClearHistory(); |
||||
|
||||
string startingText = @"This is test [&a|b|c]"; |
||||
string startingTextA = @"This is test a"; |
||||
string startingTextB = @"This is test b"; |
||||
string startingTextC = @"This is test c"; |
||||
|
||||
string res = string.Empty; |
||||
|
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextA); |
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextB); |
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextC); |
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextA); |
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextB); |
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextC); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleOnceSelection() |
||||
{ |
||||
Fungus.TextVariationHandler.ClearHistory(); |
||||
|
||||
string startingText = @"This is test [!a|b|c]"; |
||||
string startingTextA = @"This is test a"; |
||||
string startingTextB = @"This is test b"; |
||||
string startingTextC = @"This is test c"; |
||||
string startingTextD = @"This is test "; |
||||
|
||||
string res = string.Empty; |
||||
|
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextA); |
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextB); |
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextC); |
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextD); |
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextD); |
||||
} |
||||
|
||||
[Test] |
||||
public void NestedSelection() |
||||
{ |
||||
Fungus.TextVariationHandler.ClearHistory(); |
||||
|
||||
string startingText = @"This is test [a||sub [~a|b]|[!b|[~c|d]]]"; |
||||
string startingTextA = @"This is test a"; |
||||
string startingTextBlank = @"This is test "; |
||||
string startingTextSubA = @"This is test sub a"; |
||||
string startingTextSubB = @"This is test sub b"; |
||||
string startingTextB = @"This is test b"; |
||||
string startingTextC = @"This is test c"; |
||||
string startingTextD = @"This is test d"; |
||||
|
||||
string res = string.Empty; |
||||
|
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextA); |
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextBlank); |
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
if(res != startingTextSubA && res != startingTextSubB) |
||||
{ |
||||
Assert.Fail(); |
||||
} |
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
Assert.AreEqual(res, startingTextB); |
||||
res = Fungus.TextVariationHandler.SelectVariations(startingText); |
||||
if (res != startingTextC && res != startingTextD) |
||||
{ |
||||
Assert.Fail(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 8769bf7410785704f95413bb0865079c |
||||
MonoImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
Loading…
Reference in new issue