public void SetNewWeight_Min_Boundary() { var weight = new WeightItem(2, 100); var newWeight = weight.SetNewWeight(-2); Assert.AreEqual(1, newWeight.Weight); }
public void SetNewWeight_Max_Boundary() { var weight = new WeightItem(90, 100); var newWeight = weight.SetNewWeight(11); Assert.AreEqual(100, newWeight.Weight); }
private static IResourceManager <string> CreateResourceManager(string[] baseUrls) { var dict = baseUrls.ToDictionary(x => x, x => WeightItem.CreateDefaultItem()); var mgr = new ResourceManager <string>(dict, new AgodaWeightManipulationStrategy()); return(mgr); }
public void UpdateBaseUrls(string[] baseUrls) { var dict = baseUrls .Distinct() .ToDictionary(x => x, _ => WeightItem.CreateDefaultItem()); UrlResourceManager.UpdateResources(dict); }
public void UpdateWeight_Various(bool isSuccess) { var strats = NoopWeightManipulationStrategy.Default; var oldWeight = new WeightItem(50, 100); var newWeight = strats.UpdateWeight("tgt", oldWeight, isSuccess); Assert.AreEqual(oldWeight, newWeight); }
public void SetUp() { _dict = new Dictionary <string, WeightItem>() { { "tgt", new WeightItem(10, 10) } }.ToImmutableDictionary(); _newWeightItem = new WeightItem(50, 100); _strats = new Mock <IWeightManipulationStrategy>(); _strats.Setup(x => x.UpdateWeight( It.IsAny <string>(), It.IsAny <WeightItem>(), It.IsAny <bool>())) .Returns(() => _newWeightItem); }
public void SetNewWeight_Copy() { var weight = new WeightItem(50, 100); var newWeight = weight.SetNewWeight(20); // Delta Assert.AreEqual(70, newWeight.Weight); // Copy MaxWeight Assert.AreEqual(100, newWeight.MaxWeight); // Do not mutate original weight Assert.AreEqual(50, weight.Weight); Assert.AreEqual(100, weight.MaxWeight); }
public void UpdateWeight_Success() { var result = new WeightItem(10, 10); var inc = new Mock <IWeightManipulationStrategy>(); inc.Setup(x => x.UpdateWeight( "tgt", It.IsAny <WeightItem>(), true)) .Returns(result); var strats = new SplitWeightManipulationStrategy(inc.Object, Mock.Of <IWeightManipulationStrategy>()); var newWeight = strats.UpdateWeight("tgt", new WeightItem(50, 100), true); Assert.AreEqual(result, newWeight); }
public void UpdateWeight_Failure() { var result = new WeightItem(10, 10); var dec = new Mock <IWeightManipulationStrategy>(); dec.Setup(x => x.UpdateWeight( "tgt", It.IsAny <WeightItem>(), false)) .Returns(result); var strats = new SplitWeightManipulationStrategy(Mock.Of <IWeightManipulationStrategy>(), dec.Object); var newWeight = strats.UpdateWeight("tgt", new WeightItem(50, 100), false); Assert.AreEqual(result, newWeight); }
private void ConstructPowerUpList() { _powerUps = new List <WeightItem>(); float total = 0; for (int i = 0; i < _powerUpsArray.Length; i++) { var weightItem = new WeightItem(); weightItem.Item = _powerUpsArray[i].gameObject; weightItem.Weight = _powerUpsWeights[i]; total += weightItem.Weight; weightItem.CalculatedWeight = total; _powerUps.Add(weightItem); } }
public void UpdateWeight_ReplacementWhenWeightChange() { _newWeightItem = _dict["tgt"]; var mgr = ResourceManager.Create(new[] { "tgt" }); var onUpdateWeightCount = 0; mgr.OnUpdateWeight += (sender, args) => { onUpdateWeightCount++; }; var oldResources = mgr.Resources; mgr.UpdateWeight("tgt", false); Assert.AreEqual(1, onUpdateWeightCount); Assert.AreNotSame(oldResources, mgr.Resources); }
public void UpdateResources_AgodaWeight() { var mgr = ResourceManager.Create(new[] { "remove", "keep", "keep_unchanged" }); // Change weight mgr.UpdateWeight("keep", false); mgr.UpdateResources(new[] { "keep", "keep_unchanged", "add" }); // add Assert.IsTrue(WeightItem.CreateDefaultItem().Equals(mgr.Resources["add"])); // keep Assert.AreEqual(WeightItem.CreateDefaultItem().MaxWeight, mgr.Resources["keep"].MaxWeight); Assert.AreNotEqual(WeightItem.CreateDefaultItem().Weight, mgr.Resources["keep"].Weight); // keep_unchanged Assert.IsTrue(WeightItem.CreateDefaultItem().Equals(mgr.Resources["keep_unchanged"])); // remove Assert.IsFalse(mgr.Resources.ContainsKey("remove")); }
public void UpdateWeight_OnAllSourcesReachBottom_Failure() { _newWeightItem = new WeightItem(1, 100); var mgr = new ResourceManager <string>(_dict, _strats.Object); var onEventRaised = 0; mgr.OnAllSourcesReachBottom += (sender, args) => { onEventRaised++; Assert.AreEqual(_newWeightItem, args.NewResources.Values.First()); }; mgr.UpdateWeight("tgt", false); Assert.AreEqual(1, onEventRaised); _strats.Verify(x => x.UpdateWeight( "tgt", _dict["tgt"], false), Times.Once); }
public void UpdateWeight_OnUpdateWeight_Unchanged() { _newWeightItem = _dict["tgt"]; var mgr = new ResourceManager <string>( _dict, _strats.Object); var onUpdateWeightCount = 0; mgr.OnUpdateWeight += (sender, args) => { onUpdateWeightCount++; }; mgr.UpdateWeight("tgt", true); Assert.AreEqual(0, onUpdateWeightCount); _strats.Verify(x => x.UpdateWeight( "tgt", _dict["tgt"], true), Times.Once); }
public GrpcChannelManager(string[] urls, TimeSpan?timeout, int maxRetry = 1) { _shouldRetry = GetRetryCountPredicate(maxRetry); _timeout = timeout; var resourceDict = CreateResourceDictionary(urls.ToDictionary(x => x, x => WeightItem.CreateDefaultItem())); ResourceManager = new ResourceManager <GrpcResource>(resourceDict, new AgodaWeightManipulationStrategy()); }
public WeightItem UpdateWeight <T>(T source, WeightItem originalWeight, bool isSuccess) { var delta = Delta * (isSuccess ? 1 : -1); return(originalWeight.SetNewWeight(delta)); }
public void Weight_TestMethod() { WeightItem item = WeightItem.Factory.Create(1000, U.Lb); TestUnitClass(item, new string[] { U.Kg, U.Lb }, 1000, 9); }
public WeightItem UpdateWeight <T>(T source, WeightItem originalWeight, bool isSuccess) { var strategy = isSuccess ? Increment : Decrement; return(strategy.UpdateWeight(source, originalWeight, isSuccess)); }
public void UpdateResources(string[] urls) { var resources = urls.ToDictionary(x => x, x => WeightItem.CreateDefaultItem()); UpdateResources(resources); }
public void AddWeightItem(WeightItem weightItem) { Items.Add(weightItem); }
public WeightItem UpdateWeight <T>(T source, WeightItem originalWeight, bool isSuccess) { return(originalWeight); }