public void ChangeRequired1() { Money moneyFloat = SampleFloat(); decimal originalFloat = moneyFloat.Total; ChangeAlgorithm algo = new ChangeAlgorithm(); decimal price = 2.3M; Money tendered = new Money(); tendered.Add(DenominationEnum.OneEuro, 2); tendered.Add(DenominationEnum.TenCents, 4); Money change; bool result = algo.DetermineChange(moneyFloat, tendered, price, out change); Assert.IsTrue(result); Assert.AreEqual(0.1M, change.Total, "Change total incorrect. Change expected."); Assert.AreEqual(originalFloat + price, moneyFloat.Total, "Float incorrect."); Assert.AreEqual(1, change[DenominationEnum.TenCents].NumberOfCoins, "Incorrect change. 10 cents."); Assert.AreEqual(0, change[DenominationEnum.TwentyCents].NumberOfCoins, "Incorrect change. 20 cents."); Assert.AreEqual(0, change[DenominationEnum.FiftyCents].NumberOfCoins, "Incorrect change. 50 cents."); Assert.AreEqual(0, change[DenominationEnum.OneEuro].NumberOfCoins, "Incorrect change. 1 Euro."); Assert.AreEqual(0, change[DenominationEnum.TwoEuro].NumberOfCoins, "Incorrect change. 2 Euro."); Assert.AreEqual(103, moneyFloat[DenominationEnum.TenCents].NumberOfCoins, "Incorrect float. 10 cents."); Assert.AreEqual(100, moneyFloat[DenominationEnum.TwentyCents].NumberOfCoins, "Incorrect float. 20 cents."); Assert.AreEqual(100, moneyFloat[DenominationEnum.FiftyCents].NumberOfCoins, "Incorrect float. 50 cents."); Assert.AreEqual(102, moneyFloat[DenominationEnum.OneEuro].NumberOfCoins, "Incorrect float. 1 Euro."); Assert.AreEqual(100, moneyFloat[DenominationEnum.TwoEuro].NumberOfCoins, "Incorrect float. 2 Euro."); }
/// <summary> /// /// </summary> public void TestMixedSimpleAdd() { // [12 CHF] + [7 USD] == {[12 CHF][7 USD]} Money[] bag = { f12CHF, f7USD }; MoneyBag expected = new MoneyBag(bag); Assertion.AssertEquals(expected, f12CHF.Add(f7USD)); }
public void TestAdd() { _target.SetFieldOrProperty(MEMBER_VARIABLE_NAME_VALUE, 100); Assert.ThrowsException <ArgumentNullException>(() => _money.Add(null)); _money.Add(new Money(20)); Assert.AreEqual(( int )_target.GetFieldOrProperty(MEMBER_VARIABLE_NAME_VALUE), 120); _money.Add(new Money(-60)); Assert.AreEqual(( int )_target.GetFieldOrProperty(MEMBER_VARIABLE_NAME_VALUE), 60); }
public void AddNew() { amountOfBees.Add(BeesPerSecond); Money cap = capacityBase.Promille(Mathf.FloorToInt(capacityMult * 1000)); if (cap.isLower(amountOfBees)) { amountOfBees.Clone(cap); } }
/// <summary> /// Gives money in credit or returns deposit, if possible. /// Gives whole sum or gives nothing. /// Checks inside. Return false if didn't give credit. /// </summary> public bool GiveCredit(Agent taker, MoneyView desiredCredit) // todo check { if (taker.deposits.isNotZero()) // has deposit (meaning, has no loans) { if (desiredCredit.isBiggerThan(taker.deposits)) // loan is bigger than this deposit { MoneyView returnedDeposit = ReturnDeposit(taker, taker.deposits); if (returnedDeposit.isSmallerThan(taker.deposits)) { return(false);// if can't return deposit than can't give credit for sure } //returnedMoney = new ReadOnlyValue(0f); MoneyView restOfTheSum = desiredCredit.Copy().Subtract(returnedDeposit); if (CanGiveCredit(taker, restOfTheSum)) { taker.loans.Set(restOfTheSum);//important givenCredits.Add(restOfTheSum); PayWithoutRecord(taker, restOfTheSum, Register.Account.BankOperation); return(true); } else { return(false); } } else // no need for credit, just return deposit { // if can't return deposit than can't give credit for sure if (CanReturnDeposit(taker, desiredCredit)) { ReturnDeposit(taker, desiredCredit); return(true); } else { return(false); } } } else { if (CanGiveCredit(taker, desiredCredit)) { taker.loans.Add(desiredCredit); givenCredits.Add(desiredCredit); PayWithoutRecord(taker, desiredCredit, Register.Account.BankOperation); return(true); } else { return(false); } } }
public void MixedSimpleAdd() { // [12 CHF] + [7 USD] == {[12 CHF][7 USD]} Money[] bag = { f12CHF, f7USD }; MoneyBag expected = new MoneyBag(bag); Assert.AreEqual((object)expected, f12CHF.Add(f7USD)); }
public void Build(Vector3 Position, Quaternion Rotation) { if (money.money >= turretCost && turret != null) { money.Add(-turretCost); GameObject obj = (GameObject)Instantiate(selectedTurret.gameObject, Position, Rotation); turret = null; turretCost = 0; CancelButton.SetActive(false); } }
private Money SampleMoney() { Money money = new Money(); money.Add(DenominationEnum.TenCents, 100); money.Add(DenominationEnum.TwentyCents, 100); money.Add(DenominationEnum.FiftyCents, 100); money.Add(DenominationEnum.OneEuro, 100); money.Add(DenominationEnum.TwoEuro, 100); return(money); }
public void PlayerPaysRentToOwnerOfSingleRailroad() { var expectedRent = new Money(25); var expectedOwnerMoney = startingMoney.Add(expectedRent); var expectedPlayerMoney = startingMoney.Remove(expectedRent); var rentAction = new RailroadRentAction(new FakeBoard(numberOfRailroadsOwnedByPlayer: 1)); rentAction.ProcessAction(player, fakeProperty); Assert.AreEqual(expectedOwnerMoney, owner.Balance); Assert.AreEqual(expectedPlayerMoney, player.Balance); }
static void Main(string[] args) { var jpy = new Money(1000, "KRW"); var usd = new Money(10, "USD"); var result = jpy.Add(usd); // 예외 발생 }
public void TestMoneyAdd() { Money expected = new Money(1000, "TWD"); Money actual = new Money(500, "TWD"); Assert.AreNotEqual(expected, actual.Add(new Money(200, "TWD"))); }
static void Main(string[] args) { var jpy = new Money(1000, "JPY"); var usd = new Money(10, "USD"); var result = jpy.Add(usd); // 例外が送出される }
public bool IsCountryOwnsControlPacket() { Money ownedByAnyCountry = new Money(0m); Money total = new Money(0m); foreach (var item in GetAll()) { var value = item.Value.GetShare(); if (item.Key is Country) { ownedByAnyCountry.Add(value); } total.Add(value); } var res = new Procent(ownedByAnyCountry, total, false); // to avoid console spam with ghost factories if (res.isBiggerOrEqual(Procent._50Procent)) { return(true); } else { return(false); } }
//public static IEnumerable<FactoryType> getAllResourceTypes(Country country) //{ // foreach (var next in getAllInventedTypes(country)) // if (next.isResourceGathering()) // yield return next; //} //public static IEnumerable<FactoryType> getAllNonResourceTypes(Country country) //{ // foreach (var next in getAllInventedTypes(country)) // if (!next.isResourceGathering()) // yield return next; //} /// <summary> ///Returns new value /// </summary> public Money GetBuildCost() { Money result = Game.market.getCost(GetBuildNeeds()); result.Add(Options.factoryMoneyReservePerLevel); return(result); }
private void OnTriggerEnter(Collider other) { PlayerController player = other.gameObject.GetComponent <PlayerController>(); if (player && player.enemyGameObject != null) { StateController enemyController = player.enemyGameObject.gameObject.GetComponent <StateController>(); if (enemyController && enemyController.hasDocuments) { hasDocuments = true; } if (ObjectManager.Instance.Enemies.Remove(player.enemyGameObject)) { Destroy(player.enemyGameObject); Money.Add(player.enemyGameObject.GetComponent <MoneyValue> ().moneyValue); MoneyController.Instance.UpdateMoneyOnHUD(); } player.enemyGameObject = null; player.animator.SetBool("RightHandUp", false); player.animator.SetBool("LeftHandUp", false); player.isChasing = false; if (hasDocuments) { player.hasDocuments = true; player.documents = Instantiate(VisibilityManager.Instance.playerDocuments, player.gameObject.transform); player.documents.GetComponent <Collider>().enabled = false; player.animator.SetBool("RightHandUp", true); } } }
public void Add(Money m) { if (m.power == power) { bigPart += m.bigPart; smallPart += m.smallPart; verySmallPart += m.verySmallPart; if (verySmallPart >= 1000) { smallPart++; verySmallPart -= 1000; } if (smallPart >= 1000) { bigPart++; smallPart -= 1000; } } else if (m.power == power - 1) // if m is lower by 1 power { smallPart += m.bigPart; verySmallPart += m.smallPart; if (verySmallPart >= 1000) { smallPart++; verySmallPart -= 1000; } if (smallPart >= 1000) { bigPart++; smallPart -= 1000; } } else if (m.power == power - 2) // if m is lower by 2 power { verySmallPart += m.bigPart; if (verySmallPart >= 1000) { smallPart++; verySmallPart -= 1000; } if (smallPart >= 1000) { bigPart++; smallPart -= 1000; } } else if (m.power < power) { return; } else { m.Add(this); power = m.power; bigPart = m.bigPart; smallPart = m.smallPart; } CheckPower(); }
public void AddingSameCurrenciesAddMethod() { var result = Money.Add(_cad1, _cad3); Assert.AreEqual(15, result.Amount); Assert.AreEqual(_cad3, result); }
public void AddingNzdToAudViaMethodThrowsException() { Money aud = new Money(12.5m, CurrencyFixture.AustralianDollar); Money nzd = new Money(12.5m, CurrencyFixture.NewZealandDollar); Money result = aud.Add(nzd); }
public Money ReadMoney() { var money = new Money(); var stream = new StreamReader(new FileStream(_path, FileMode.Open)); stream.ReadLine(); var str = stream.ReadLine(); if (str != null) { var strs = str.Split(','); try { foreach (var item in strs) { var temp = Regex.Matches(item, @"\d+"); var number = int.Parse(temp[1].ToString()); var nominal = int.Parse(temp[0].ToString()); money.Add(nominal, number); } } catch (Exception e) { Log.Error("Parse error: " + e.Message); } } stream.Close(); return(money); }
/// <summary> call it BEFORE opening enterprise /// Returns salary of a factory with lowest salary in province. If only one factory in province, then returns Country.minsalary /// \nCould auto-drop salary on minSalary of there is problems with inputs /// Returns new value</summary> public MoneyView getLocalMinSalary() { MoneyView res; if (allFactories.Count <= 1) // first enterprise in province { res = Country.getMinSalary(); } else { Money minSalary = getLocalMaxSalary().Copy(); foreach (Factory factory in allFactories) { if (factory.IsOpen && factory.HasAnyWorkforce())//&& !factory.isJustHiredPeople() { if (factory.getSalary().isSmallerThan(minSalary)) { minSalary = factory.getSalary(); } } } minSalary.Add(0.012m); //connected to ChangeSalary() res = minSalary; } //if (res == 0f) // res = Options.FactoryMinPossibleSalary; return(res); }
public void Adding_the_opposite_returns_zero_money(Money <string> x) { var zero = Money.Create(0, x.Currency); Assert.Equal(zero, x + (-x)); Assert.Equal(zero, x.Add(x.Negate())); }
public Money ReadMoney() { var money = new Money(); using (var sr = new StreamReader(_path)) { while (!sr.EndOfStream) { var readLine = sr.ReadLine(); if (readLine != null) { try { var temp = readLine.Split(' '); var banknoteNomimal = int.Parse(temp[0]); var banknotesCount = int.Parse(temp[1]); money.Add(banknoteNomimal, banknotesCount); } catch (Exception e) { Log.Error("Parse error: " + e.Message); } } } } return(money); }
/// <summary> Spawns a random entity in the world </summary> public void SpawnEntity() { NPC entity = null; switch (random.Next(0, 3)) // Number is >= 0 and < 3 { // Monster case 0: entity = RandomMonster(); Monsters.Add((Monster)entity); this.Controls.Add(entity); break; // Money case 1: entity = RandomMoney(); Money.Add((Money)entity); this.Controls.Add(entity); break; // Health case 2: entity = RandomHealth(); Health.Add((Health)entity); this.Controls.Add(entity); break; default: break; } }
public void ChangeRequired_Only10CentCoinsInFloat() { Money moneyFloat = new Money(); moneyFloat.Add(DenominationEnum.TenCents, 30); //only 10 cent coins in float decimal originalFloat = moneyFloat.Total; ChangeAlgorithm algo = new ChangeAlgorithm(); decimal price = 1.4M; Money tendered = new Money(); tendered.Add(DenominationEnum.TwoEuro, 1); Money change; bool result = algo.DetermineChange(moneyFloat, tendered, price, out change); Assert.IsTrue(result); Assert.AreEqual(tendered.Total - price, change.Total, "Change total incorrect. Change expected."); Assert.AreEqual(originalFloat + price, moneyFloat.Total, "Float incorrect."); Assert.AreEqual(6, change[DenominationEnum.TenCents].NumberOfCoins, "Incorrect change. 10 cents."); Assert.AreEqual(0, change[DenominationEnum.TwentyCents].NumberOfCoins, "Incorrect change. 20 cents."); Assert.AreEqual(0, change[DenominationEnum.FiftyCents].NumberOfCoins, "Incorrect change. 50 cents."); Assert.AreEqual(0, change[DenominationEnum.OneEuro].NumberOfCoins, "Incorrect change. 1 Euro."); Assert.AreEqual(0, change[DenominationEnum.TwoEuro].NumberOfCoins, "Incorrect change. 2 Euro."); Assert.AreEqual(24, moneyFloat[DenominationEnum.TenCents].NumberOfCoins, "Incorrect float. 10 cents."); Assert.AreEqual(0, moneyFloat[DenominationEnum.TwentyCents].NumberOfCoins, "Incorrect float. 20 cents."); Assert.AreEqual(0, moneyFloat[DenominationEnum.FiftyCents].NumberOfCoins, "Incorrect float. 50 cents."); Assert.AreEqual(0, moneyFloat[DenominationEnum.OneEuro].NumberOfCoins, "Incorrect float. 1 Euro."); Assert.AreEqual(1, moneyFloat[DenominationEnum.TwoEuro].NumberOfCoins, "Incorrect float. 2 Euro."); }
//public static IEnumerable<FactoryType> getAllResourceTypes(Country country) //{ // foreach (var next in getAllInventedTypes(country)) // if (next.isResourceGathering()) // yield return next; //} //public static IEnumerable<FactoryType> getAllNonResourceTypes(Country country) //{ // foreach (var next in getAllInventedTypes(country)) // if (!next.isResourceGathering()) // yield return next; //} /// <summary> ///Returns new value /// </summary> public MoneyView GetBuildCost() { Money result = World.market.getCost(GetBuildNeeds()).Copy(); result.Add(Options.factoryMoneyReservePerLevel); return(result); }
public void CountDeMonet() { Money money = new Money(42.00); money.Add(2); MoneyAssert.AssertNoCents(money); }
public void CannotGiveChange_FloatNotEmpty() { Money moneyFloat = new Money(); moneyFloat.Add(DenominationEnum.FiftyCents, 1); decimal originalFloat = moneyFloat.Total; ChangeAlgorithm algo = new ChangeAlgorithm(); decimal price = 0.1M; Money tendered = new Money(); tendered.Add(DenominationEnum.TwentyCents, 1); Money change; bool result = algo.DetermineChange(moneyFloat, tendered, price, out change); Assert.IsFalse(result); Assert.AreEqual(originalFloat, moneyFloat.Total, "Float incorrect."); Assert.AreEqual(0, moneyFloat[DenominationEnum.TenCents].NumberOfCoins, "Incorrect float. 10 cents."); Assert.AreEqual(0, moneyFloat[DenominationEnum.TwentyCents].NumberOfCoins, "Incorrect float. 20 cents."); Assert.AreEqual(1, moneyFloat[DenominationEnum.FiftyCents].NumberOfCoins, "Incorrect float. 50 cents."); Assert.AreEqual(0, moneyFloat[DenominationEnum.OneEuro].NumberOfCoins, "Incorrect float. 1 Euro."); Assert.AreEqual(0, moneyFloat[DenominationEnum.TwoEuro].NumberOfCoins, "Incorrect float. 2 Euro."); }
public bool DetermineChange(Money moneyFloat, Money tendered, decimal price, out Money change) { if (IsTenderedTooLittle(tendered, price, out change)) { return(false); } if (IsTenderedEqualPrice(moneyFloat, tendered, price, out change)) { return(true); } moneyFloat.Add(tendered); //add the new coins to the float change = CalculateChange(moneyFloat, tendered, price); //attempt to calculate the change if (change == null) { moneyFloat.Subtract(tendered); //no change => so revert the float return(false); } else { moneyFloat.Subtract(change); //change found => subtract change from the float return(true); } }
/// <summary> /// /// </summary> public void TestSimpleBagAdd() { // [14 CHF] + {[12 CHF][7 USD]} == {[26 CHF][7 USD]} Money[] bag = { new Money(26, "CHF"), new Money(7, "USD") }; MoneyBag expected = new MoneyBag(bag); Assertion.AssertEquals(expected, f14CHF.Add(fMB1)); }
public void Add_SameCurrency_AnotherMoneyWithAddedUpamount() { Money fifteenQuid = Money.Add(fiver, tenner); Assert.That(fifteenQuid, Is.Not.SameAs(fiver).And.Not.SameAs(tenner)); Assert.That(fifteenQuid.Amount, Is.EqualTo(15)); Assert.That(fifteenQuid.CurrencyCode, Is.EqualTo(CurrencyIsoCode.GBP)); }
public void AddGstReturnsOriginalMoneyIncreasedByGSTAmount() { Money money = new Money(1900.5m, CurrencyFixture.NewZealandDollar); Gst gst = new Gst(12.5m); Money expected = money.Multiply(gst.Multiplier); Money actual = money.Add(gst); actual.Should().Be(expected); }
public void AddingSomeMoney(decimal value1, decimal value2, decimal expected) { var m = new Money(value1); var m2 = new Money(value2); Assert.That(new Money(expected), Is.EqualTo(m.Add(m2))); }