public IEnumerator MangedTest() { using (var tester = new Tester()) { var counter = new Counter(); BootParam prm = new BootParam(); prm.BootContents.Add(new MainTestParam { Counter = counter }); yield return(WrapTask(tester.Controller.Boot(prm))); var manded = tester.Controller.Get <IHasManagedHolder>(); bool dispose = false; // disposed時にアクションを発火するように登録 var action = manded.Manage(() => dispose = true); Assert.IsFalse(dispose); //Unmanageで解放される manded.Unmanage(action); Assert.IsTrue(dispose); //再登録 dispose = false; manded.Manage(() => dispose = true); //非同期を登録 var asyncDispose = new AsyncDispose(); manded.ManageAsync(asyncDispose); tester.Message(MainTestContent.Event.Switch, counter); //直ぐには実行されない Assert.IsFalse(asyncDispose.Disposed); yield return(counter.Wait("Run", 2)); yield return(tester.Close()); Assert.IsTrue(dispose); Assert.IsTrue(asyncDispose.Disposed); } }
private IEnumerator VerifyCompressionSupport(string url) { yield return(new WaitForEndOfFrame()); var request = (HttpWebRequest)WebRequest.Create(url); request.AutomaticDecompression = DecompressionMethods.GZip; var result = request.BeginGetResponse(null, null); yield return(new WaitForIAsyncResult(result)); NAssert.DoesNotThrow(() => { using (var response = (HttpWebResponse)request.EndGetResponse(result)) { Assert.AreEqual(response.StatusCode, HttpStatusCode.OK, "Unexpected HTTP response code"); var encoding = response.ContentEncoding.ToLower(); Assert.IsTrue(encoding.Contains("gzip"), string.Format("Expected: {0}, Actual: {1}", "gzip", encoding)); } }); yield return(new WaitForEndOfFrame()); }
public static Item Create(PresetId id) { if (allSprites == null) { allSprites = Resources.LoadAll <Sprite> ("items"); } var preset = itemPresets [(int)id]; Item item = new Item(); item.group = preset.group; item.type = preset.type; item.name = preset.name; item.quality = preset.quality; item.preset = preset; item.stack = 1; Assert.IsTrue(preset.spriteId < allSprites.Length); item.sprite = allSprites[preset.spriteId]; Assert.IsNotNull(item.sprite); return(item); }
public void MessageTest3() { EventCall call = new EventCall(); int count1 = 0; int count2 = 0; int count3 = 0; var path1 = call.Subscribe(TestEvent.Event1, () => count1++); var path2 = call.Subscribe(TestEvent.Event1, () => count2++); var path3 = call.Subscribe(TestEvent.Event1, () => count3++); //メッセージは一番最初に登録された物が優先される for (int i = 0; i < 5; i++) { Assert.IsTrue(call.Message(TestEvent.Event1)); Assert.AreEqual(count1, 1 + i); Assert.AreEqual(count2, 0); Assert.AreEqual(count3, 0); } //一つ解除する path1.Dispose(); //ブロードキャストは全ての登録イベントに発火する for (int i = 0; i < 5; i++) { Assert.IsTrue(call.Broadcast(TestEvent.Event1)); Assert.AreEqual(count1, 5); Assert.AreEqual(count2, 1 + i); Assert.AreEqual(count3, 1 + i); } path2.Dispose(); path3.Dispose(); //全て解除すると発火されない for (int i = 0; i < 5; i++) { Assert.IsFalse(call.Broadcast(TestEvent.Event1)); Assert.AreEqual(count1, 5); Assert.AreEqual(count2, 5); Assert.AreEqual(count3, 5); } }
public void SubCallTest() { EventCall root = new EventCall(); EventCall call1 = root.SubCall(); EventCall call2 = root.SubCall(); EventCall call3 = root.SubCall(); EventCall call4 = call1.SubCall(); EventCall call5 = call4.SubCall(); int ret = 0; var path1 = call1.Subscribe(TestEvent.Event1, () => ret = 1); call2.Subscribe(TestEvent.Event1, () => ret = 2); call3.Subscribe(TestEvent.Event1, () => ret = 3); call4.Subscribe(TestEvent.Event1, () => ret = 4); call5.Subscribe(TestEvent.Event1, () => ret = 5); //メッセージが伝播してcall1優先される Assert.IsTrue(root.Message(TestEvent.Event1)); Assert.AreEqual(ret, 1); //メッセージが優先される Assert.IsTrue(call2.Message(TestEvent.Event1)); Assert.AreEqual(ret, 2); Assert.IsTrue(call3.Message(TestEvent.Event1)); Assert.AreEqual(ret, 3); //パスがなくなったので、サブコールのイベントが呼ばれる path1.Dispose(); Assert.IsTrue(root.Message(TestEvent.Event1)); Assert.AreEqual(ret, 4); //子のサブコールも解放される call1.Dispose(); Assert.IsFalse(call5.Message(TestEvent.Event1)); Assert.AreEqual(ret, 4); Assert.IsTrue(root.Message(TestEvent.Event1)); Assert.AreEqual(ret, 2); }
public static void HardAssert(bool isTrue, string message = "") { if (!Debug.isDebugBuild) { UAssert.raiseExceptions = true; } if (message != "") { UAssert.IsTrue(isTrue, message); } else { UAssert.IsTrue(isTrue); } if (!isTrue) { Debug.Break(); } if (!Debug.isDebugBuild) { UAssert.raiseExceptions = false; } }
public void TriggerTest5() { //複数の結果をまとめる int[] input = new int[] { 1, 5, 7, 3, 5, 7 }; var triggers = new List <Trigger <int> >(); for (int i = 0; i < input.Length; i++) { triggers.Add(new Trigger <int>()); } var combine = Trigger.Combine(triggers.Select(x => x.Action).ToArray()); //まだ発火していない。 Assert.IsFalse(combine.Fired); combine.Add(x => { for (int i = 0; i < input.Length; i++) { Assert.AreEqual(x[i], input[i], "入力と同じ"); } }); for (int i = 0; i < input.Length; i++) { triggers[i].Fire(input[i]); if (i == input.Length - 1) { Assert.IsTrue(combine.Fired); } else { Assert.IsFalse(combine.Fired); } } //引数がなければすぐに発火される Assert.IsTrue(Trigger.Combine().Fired); Assert.IsTrue(Trigger.Combine <bool>().Fired); }
public void Test2() { //データクラスのセーブ using (var ctx = new Context("Test2")) { TestData data = null; for (int i = 0; i < 2; i++) { ctx.Save.TryGet(out data); Assert.IsTrue(string.IsNullOrEmpty(data.TestString)); Assert.IsTrue(data.InitCheck); Assert.AreEqual(data.OldVersion, 0); data.TestString = "Test"; } data.SetDitry(); ctx.Save.TryGet(out data); Assert.IsFalse(string.IsNullOrEmpty(data.TestString)); Assert.IsFalse(data.InitCheck); Assert.AreEqual(data.OldVersion, 0); data.SetDitry(true); TestData.TestVersion = 2; ctx.Save.TryGet(out data); Assert.AreEqual(data.TestString, "Test"); Assert.IsFalse(data.InitCheck); Assert.AreEqual(data.OldVersion, 1); data.TestString = "TestTest"; data.SetDitry(true); ctx.Save.TryGet(out data); Assert.AreEqual(data.TestString, "TestTest"); Assert.IsFalse(data.InitCheck); Assert.AreEqual(data.OldVersion, 0); } }
public void MessageTest2() { EventCall call = new EventCall(); int ret = 0; int count = 0; var path = call.Subscribe(TestEvent.Event1, (int val) => { ret = val; count++; }); //イベントを発行 Assert.IsTrue(call.Message(TestEvent.Event1, 5)); Assert.AreEqual(ret, 5); Assert.AreEqual(count, 1); //イベントを発行 Assert.IsTrue(call.Message(TestEvent.Event1, 7)); Assert.AreEqual(ret, 7); Assert.AreEqual(count, 2); //単発イベントでは発火しない Assert.IsFalse(call.Message(TestEvent.Event1)); Assert.AreEqual(ret, 7); Assert.AreEqual(count, 2); //違う方のイベントでは発火しない Assert.IsFalse(call.Message(TestEvent.Event1, 0.4f)); Assert.AreEqual(ret, 7); Assert.AreEqual(count, 2); //登録していないイベント Assert.IsFalse(call.Message(TestEvent.Event2, 4)); Assert.AreEqual(count, 2); //パスを解除 path.Dispose(); Assert.IsFalse(call.Message(TestEvent.Event1, 22)); Assert.AreEqual(ret, 7); Assert.AreEqual(count, 2); }
/// <summary> /// Adds the given item to this priority queue with the given weight. /// </summary> public void Add(T item, float weight) { Assert.IsTrue(!itemWeights.ContainsKey(item) && !sortedItems.Contains(item)); itemWeights.Add(item, weight); //Insert the item based on weight. int i; for (i = 0; i < sortedItems.Count; ++i) { float tempWeight = itemWeights[sortedItems[i]]; if ((IsAscending && tempWeight < weight) || (!IsAscending && tempWeight > weight)) { sortedItems.Insert(i, item); break; } } if (i == sortedItems.Count) { sortedItems.Add(item); } }
public void WordsetCheckerJISKana(string fileName) { var sectionRegex = @"\{__[\w|_]+__\}"; var jsonStr = AssetDatabase.LoadAssetAtPath <TextAsset>($"Assets/Wordset/Short/{fileName}.json"); var problemData = JsonUtility.FromJson <SentenceData>(jsonStr.text); var wordSetDict = new Dictionary <string, List <(string originSentence, string typeSentence)> >(); foreach (var word in problemData.words) { var wordSection = word.wordSection; var wordInfo = (word.sentence, word.typeString); if (wordSetDict.ContainsKey(wordSection)) { wordSetDict[wordSection].Add(wordInfo); } else { wordSetDict[wordSection] = new List <(string, string)>() { wordInfo }; } } foreach (var key in wordSetDict.Keys) { var dictCache = wordSetDict[key]; foreach (var wordInfo in dictCache) { var tSentence = Regex.Replace(wordInfo.typeSentence, sectionRegex, ""); foreach (var ch in tSentence) { Assert.IsTrue(jisKanaValidChar.Contains(ch.ToString())); } } } }
public IEnumerator EntityBasicMaterialUpdate() { string entityId = "1"; string materialID = "a-material"; Assert.IsFalse(scene.disposableComponents.ContainsKey(materialID)); // Instantiate entity with default material TestHelpers.InstantiateEntityWithMaterial(scene, entityId, new Vector3(8, 1, 8), new BasicMaterial.Model(), materialID); var meshObject = scene.entities[entityId].meshRootGameObject; Assert.IsTrue(meshObject != null, "Every entity with a shape should have the mandatory 'Mesh' object as a child"); var meshRenderer = meshObject.GetComponent <MeshRenderer>(); var materialComponent = scene.disposableComponents[materialID] as BasicMaterial; yield return(materialComponent.routine); // Check if material initialized correctly { Assert.IsTrue(meshRenderer != null, "MeshRenderer must exist"); var assignedMaterial = meshRenderer.sharedMaterial; Assert.IsTrue(meshRenderer != null, "MeshRenderer.sharedMaterial must be the same as assignedMaterial"); Assert.AreEqual(assignedMaterial, materialComponent.material, "Assigned material"); } // Check default properties { Assert.IsTrue(materialComponent.material.GetTexture("_BaseMap") == null); Assert.AreApproximatelyEqual(1.0f, materialComponent.material.GetFloat("_AlphaClip")); } DCLTexture dclTexture = TestHelpers.CreateDCLTexture( scene, Utils.GetTestsAssetsPath() + "/Images/atlas.png", DCLTexture.BabylonWrapMode.MIRROR, FilterMode.Bilinear); // Update material scene.SharedComponentUpdate(materialID, JsonUtility.ToJson(new BasicMaterial.Model { texture = dclTexture.id, alphaTest = 0.5f, })); yield return(materialComponent.routine); // Check updated properties { Texture mainTex = materialComponent.material.GetTexture("_BaseMap"); Assert.IsTrue(mainTex != null); Assert.AreApproximatelyEqual(0.5f, materialComponent.material.GetFloat("_Cutoff")); Assert.AreApproximatelyEqual(1.0f, materialComponent.material.GetFloat("_AlphaClip")); Assert.AreEqual(TextureWrapMode.Mirror, mainTex.wrapMode); Assert.AreEqual(FilterMode.Bilinear, mainTex.filterMode); } }
public void FindIntersectionTests() { { var l1_p1 = new Vector2(0, 1); var l1_p2 = new Vector2(0, -1); var l2_p1 = new Vector2(-1, 0); var l2_p2 = new Vector2(1, 0); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 2); Assert.IsTrue(AreApproximatelyEqual(intersection, Vector2.zero)); } { var l1_p1 = new Vector2(0, 1); var l1_p2 = new Vector2(0, 0); var l2_p1 = new Vector2(-1, 0); var l2_p2 = new Vector2(1, 0); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 2); Assert.IsTrue(AreApproximatelyEqual(intersection, Vector2.zero)); } { var l1_p1 = new Vector2(0, 2); var l1_p2 = new Vector2(0, 1); var l2_p1 = new Vector2(-1, 0); var l2_p2 = new Vector2(1, 0); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 1); Assert.IsTrue(AreApproximatelyEqual(intersection, Vector2.zero)); } { var l1_p1 = new Vector2(0, 2); var l1_p2 = new Vector2(0, 1); var l2_p1 = new Vector2(1, 2); var l2_p2 = new Vector2(1, 1); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 0); Assert.IsTrue(float.IsInfinity(intersection.x) && float.IsInfinity(intersection.y)); } { var l1_p1 = new Vector2(1, 2); var l1_p2 = new Vector2(1, 1); var l2_p1 = new Vector2(1, -2); var l2_p2 = new Vector2(1, -1); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 3); Assert.IsTrue(float.IsInfinity(intersection.x) && float.IsInfinity(intersection.y)); } { var l1_p1 = new Vector2(1, 2); var l1_p2 = new Vector2(1, -2); var l2_p1 = new Vector2(1, 3); var l2_p2 = new Vector2(1, 1); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 4); Assert.IsTrue(float.IsInfinity(intersection.x) && float.IsInfinity(intersection.y)); } { var l1_p1 = new Vector2(1, 2); var l1_p2 = new Vector2(1, -2); var l2_p1 = new Vector2(1, 2); var l2_p2 = new Vector2(1, -2); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 4); Assert.IsTrue(float.IsInfinity(intersection.x) && float.IsInfinity(intersection.y)); } { var l1_p1 = new Vector2(1, 2); var l1_p2 = new Vector2(1, -2); var l2_p1 = new Vector2(1, -2); var l2_p2 = new Vector2(1, 2); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 4); Assert.IsTrue(float.IsInfinity(intersection.x) && float.IsInfinity(intersection.y)); } { var l1_p1 = new Vector2(0, 1); var l1_p2 = new Vector2(0, 1); var l2_p1 = new Vector2(1, 0); var l2_p2 = new Vector2(1, 0); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 4); Assert.IsTrue(float.IsInfinity(intersection.x) && float.IsInfinity(intersection.y)); } { var l1_p1 = new Vector2(0, 0); var l1_p2 = new Vector2(2, 0); var l2_p1 = new Vector2(0, 1); var l2_p2 = new Vector2(1, 0); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 2); Assert.IsTrue(AreApproximatelyEqual(intersection, l2_p2)); } { var l1_p1 = new Vector2(0, 0); var l1_p2 = new Vector2(2, 0); var l2_p1 = new Vector2(1, 0); var l2_p2 = new Vector2(0, 1); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 2); Assert.IsTrue(AreApproximatelyEqual(intersection, l2_p1)); } // Parallel segments touching at one point { var l1_p1 = new Vector2(0, 3); var l1_p2 = new Vector2(0, 5); var l2_p1 = new Vector2(0, 5); var l2_p2 = new Vector2(0, 9); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 4); Assert.IsTrue(AreApproximatelyEqual(intersection, l2_p1)); } { var l1_p1 = new Vector2(0, 5); var l1_p2 = new Vector2(0, 3); var l2_p1 = new Vector2(0, 5); var l2_p2 = new Vector2(0, 9); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 4); Assert.IsTrue(AreApproximatelyEqual(intersection, l2_p1)); } { var l1_p1 = new Vector2(0, 3); var l1_p2 = new Vector2(0, 5); var l2_p1 = new Vector2(0, 9); var l2_p2 = new Vector2(0, 5); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 4); Assert.IsTrue(AreApproximatelyEqual(intersection, l2_p2)); } { var l1_p1 = new Vector2(0, 5); var l1_p2 = new Vector2(0, 3); var l2_p1 = new Vector2(0, 9); var l2_p2 = new Vector2(0, 5); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 4); Assert.IsTrue(AreApproximatelyEqual(intersection, l2_p2)); } }
public void SimplePasses() { Assert.IsTrue(1 == 1); }
void Awake() { Assert.IsTrue(XRSettings.enabled); Assert.AreEqual("lumin", XRSettings.loadedDeviceName); IsTestFinished = true; }
public void FindIntersectionTests() { { var l1_p1 = new Vector2(0, 1); var l1_p2 = new Vector2(0, -1); var l2_p1 = new Vector2(-1, 0); var l2_p2 = new Vector2(1, 0); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 2); Assert.IsTrue(Mathf.Abs(intersection.x) < 1e-8f && Mathf.Abs(intersection.y) < 1e-8f); // intersection should be Vector2.zero } { var l1_p1 = new Vector2(0, 1); var l1_p2 = new Vector2(0, 0); var l2_p1 = new Vector2(-1, 0); var l2_p2 = new Vector2(1, 0); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 2); Assert.IsTrue(Mathf.Abs(intersection.x) < 1e-8f && Mathf.Abs(intersection.y) < 1e-8f); // intersection should be Vector2.zero } { var l1_p1 = new Vector2(0, 2); var l1_p2 = new Vector2(0, 1); var l2_p1 = new Vector2(-1, 0); var l2_p2 = new Vector2(1, 0); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 1); Assert.IsTrue(Mathf.Abs(intersection.x) < 1e-8f && Mathf.Abs(intersection.y) < 1e-8f); // intersection should be Vector2.zero } { var l1_p1 = new Vector2(0, 2); var l1_p2 = new Vector2(0, 1); var l2_p1 = new Vector2(1, 2); var l2_p2 = new Vector2(1, 1); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 0); } { var l1_p1 = new Vector2(0, 1); var l1_p2 = new Vector2(0, 1); var l2_p1 = new Vector2(1, 0); var l2_p2 = new Vector2(1, 0); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 0); } { var l1_p1 = new Vector2(0, 0); var l1_p2 = new Vector2(2, 0); var l2_p1 = new Vector2(0, 1); var l2_p2 = new Vector2(1, 0); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 1); Assert.IsTrue(intersection == l2_p2); } { var l1_p1 = new Vector2(0, 0); var l1_p2 = new Vector2(2, 0); var l2_p1 = new Vector2(1, 0); var l2_p2 = new Vector2(0, 1); int intersectionType = UnityVectorExtensions.FindIntersection(l1_p1, l1_p2, l2_p1, l2_p2, out Vector2 intersection); Assert.IsTrue(intersectionType == 2); Assert.IsTrue(intersection == l2_p1); } }