void UpdateData(Dictionary <IMRObject, ChildMatchInfo> childrenExpectedMatchInfo) { var childrenList = new List <IMRObject>(childrenExpectedMatchInfo.Keys); foreach (var child in childrenList) { var matchInfo = childrenExpectedMatchInfo[child]; var dataID = matchInfo.dataID; var updateInfo = new ChildMatchInfo { dataID = dataID, semanticTagTraits = new Dictionary <string, bool>(matchInfo.semanticTagTraits) }; // Shifting all trait values by the same amount will update the data // while maintaining the validity of this data for our test relations. foreach (var floatKVP in matchInfo.floatTraits) { var name = floatKVP.Key; var value = floatKVP.Value + 1f; updateInfo.floatTraits[name] = value; m_FloatTraitProvider.AddOrUpdateTrait(dataID, name, value); } foreach (var vector2KVP in matchInfo.vector2Traits) { var name = vector2KVP.Key; var value = vector2KVP.Value + Vector2.right; updateInfo.vector2Traits[name] = value; m_Vector2TraitProvider.AddOrUpdateTrait(dataID, name, value); } childrenExpectedMatchInfo[child] = updateInfo; } }
public void OnEnable() { ConnectDb(); m_Db.GetTraitProvider(out m_Provider); m_StartFrame = Time.frameCount; for (int i = 0; i < s_DataCount; i++) { m_TraitNames[i] = "trait" + i; m_Provider.AddOrUpdateTrait(i, m_TraitNames[i], Random.Range(-10f, 10f)); } }
public void Update() { for (int i = 0; i < s_DataCount; i++) { m_Provider.AddOrUpdateTrait(i, m_TraitNames[i], i); } }
public void TryFillRequirementsUpdate_ReturnsFalse_WhenAnyRequiredTraitNotPresent() { const int dataId = 72; var result = new QueryResult(); // none of the required traits are present yet - should fail Assert.False(m_Db.TryFillTraitRequirementsUpdate(dataId, m_TraitRequirements, result)); const int alignmentValue = 1; m_IntTraitProvider.AddOrUpdateTrait(dataId, TraitNames.Alignment, alignmentValue); m_TagTraitProvider.AddOrUpdateTrait(dataId, TraitNames.Floor, true); m_Vector2TraitProvider.AddOrUpdateTrait(dataId, TraitNames.Bounds2D, Vector2.one); // all but one of the required traits are present - should still fail Assert.False(m_Db.TryFillTraitRequirementsUpdate(dataId, m_TraitRequirements, result)); m_PoseTraitProvider.AddOrUpdateTrait(dataId, TraitNames.Pose, Pose.identity); Assert.True(m_Db.TryFillTraitRequirementsUpdate(dataId, m_TraitRequirements, result)); }
public void CacheRelationTraitReferences() { var workingIndices = new List <int> { 0, 1 }; var fulfilledIndices = new List <int>(); const string presentTrait = "present"; var go1 = new GameObject("relation trait cache test present", typeof(ProxyGroup)); go1.AddFloatRelation(presentTrait, presentTrait); m_FloatTraitProvider.AddOrUpdateTrait(10, presentTrait, 1); // the set with this relation should fail to progress to the next step, because it does not have data const string absentTrait = "absent"; var go2 = new GameObject("relation trait cache test absent", typeof(ProxyGroup)); go2.AddFloatRelation(absentTrait, absentTrait); var relations1 = TestUtils.GetRelations(go1); var relations2 = TestUtils.GetRelations(go2); var relationsCollection = new [] { relations1, relations2 }; var traitCacheCollection = new [] { new RelationTraitCache(relations1), new RelationTraitCache(relations2) }; m_Db.CacheTraitReferences(workingIndices, fulfilledIndices, relationsCollection, ref traitCacheCollection); UnityObject.DestroyImmediate(go1); UnityObject.DestroyImmediate(go2); // because one set found all traits for its relations, we should have one in the filtered indices Assert.AreEqual(1, fulfilledIndices.Count); Assert.AreEqual(0, fulfilledIndices.First()); var fulfilledCollection = traitCacheCollection[0]; Assert.True(fulfilledCollection.Fulfilled); Assert.False(traitCacheCollection[1].Fulfilled); Assert.True(fulfilledCollection.TryGetType(out List <RelationTraitCache.ChildTraits <float> > floatTraits)); foreach (var cache in floatTraits) { Assert.NotNull(cache.One); Assert.NotNull(cache.Two); } }
public void TryUpdateQueryMatchData_ReturnsUpdatedData() { var updatedFloats = new float[k_ConditionsPerType]; var updatedVector2s = new Vector2[k_ConditionsPerType]; for (var i = 0; i < k_ConditionsPerType; ++i) { var updatedFloat = MatchingFloatForIndex(i) + 1; var updatedVector2 = MatchingVector2ForIndex(i) + Vector2.right; updatedFloats[i] = updatedFloat; updatedVector2s[i] = updatedVector2; m_Db.GetTraitProvider(out MARSTraitDataProvider <float> floatTraits); m_FloatTraitProvider.AddOrUpdateTrait(k_DataID, TraitNameForIndex <float>(i), updatedFloat); m_Db.GetTraitProvider(out MARSTraitDataProvider <bool> semanticTagTraits); semanticTagTraits.AddOrUpdateTrait(k_DataID, TraitNameForIndex(i), true); m_Db.GetTraitProvider(out MARSTraitDataProvider <Vector2> vector2Traits); vector2Traits.AddOrUpdateTrait(k_DataID, TraitNameForIndex <Vector2>(i), updatedVector2); } Assert.True(m_Db.TryUpdateQueryMatchData(k_DataID, m_Conditions, m_EmptyTraitRequirements, m_QueryResult)); for (var i = 0; i < k_ConditionsPerType; ++i) { var tagTraitName = TraitNameForIndex(i); Assert.True(m_QueryResult.TryGetTrait(tagTraitName, out bool tagValue)); var floatTraitName = TraitNameForIndex <float>(i); Assert.True(m_QueryResult.TryGetTrait(floatTraitName, out float floatValue)); Assert.AreEqual(updatedFloats[i], floatValue, Mathf.Epsilon); var vector2TraitName = TraitNameForIndex <Vector2>(i); Assert.True(m_QueryResult.TryGetTrait(vector2TraitName, out Vector2 vector2Value)); Assert.AreEqual(updatedVector2s[i], vector2Value); } }
internal static void PopulateTraitProvider <T>(MARSTraitDataProvider <T> provider, Dictionary <int, T> data, string traitNamePrefix = "", int count = 1) { for (int i = 0; i < count; i++) { var traitName = string.IsNullOrEmpty(traitNamePrefix) ? TraitNameForIndex <T>(i) : count == 1 ? traitNamePrefix // inserts an exact trait name : string.Format("{0}{1}", traitNamePrefix, i); foreach (var kvp in data) { provider.AddOrUpdateTrait(kvp.Key, traitName, kvp.Value); } } }
public void OnEnable() { ConnectDb(); m_Db.GetTraitProvider(out m_Provider); m_TraitNames = new string[k_TotalDataCount]; m_StartFrame = Time.frameCount; for (int i = 0; i < k_TotalDataCount; i++) { s_NextId++; m_TraitNames[i] = "trait_" + i; s_DataIds[i] = s_NextId; m_Provider.AddOrUpdateTrait(s_NextId, m_TraitNames[i], Random.Range(-10f, 10f)); } }
public void AddGetRemove_TraitValue <T>(int id, string traitName, T traitValue) { var provider = new MARSTraitDataProvider <T>(dataId => { }, m_Db); provider.AddOrUpdateTrait(id, traitName, traitValue); T retrievedValue; provider.TryGetTraitValue(id, traitName, out retrievedValue); Assert.AreEqual(traitValue, retrievedValue); Assert.True(provider.RemoveTrait(id, traitName)); T postRemovalValue; Assert.False(provider.TryGetTraitValue(id, traitName, out postRemovalValue)); Assert.AreEqual(default(T), postRemovalValue); }
void AddDataThatMatchesQuery(Dictionary <IMRObject, ChildMatchInfo> childrenExpectedMatchInfo) { var dataID = 0; foreach (var kvp in childrenExpectedMatchInfo) { var matchInfo = kvp.Value; matchInfo.dataID = dataID; foreach (var tagKvp in matchInfo.semanticTagTraits) { m_TagTraitProvider.AddOrUpdateTrait(dataID, tagKvp.Key, tagKvp.Value); } foreach (var floatKVP in matchInfo.floatTraits) { m_FloatTraitProvider.AddOrUpdateTrait(dataID, floatKVP.Key, floatKVP.Value); } foreach (var vector2KVP in matchInfo.vector2Traits) { m_Vector2TraitProvider.AddOrUpdateTrait(dataID, vector2KVP.Key, vector2KVP.Value); } dataID++; } }
public void TryUpdateQueryMatchData_TagMatchSetToFalse_ReturnsFalse() { TestDataThatMatchesQuery(); m_TagTraitProvider.AddOrUpdateTrait(k_DataID, TraitNameForIndex(0), false); Assert.False(m_Db.TryUpdateQueryMatchData(m_DataID, m_Conditions, m_EmptyTraitRequirements, m_QueryResult)); }