public void Should_initialize_instance(decimal value) { var actual = new AUD(value); Assert.IsAssignableFrom <AUD>(actual); Assert.AreEqual(value, actual.Value, nameof(actual.Value)); }
public string convert(string code, string amount) { decimal AUD; //output amount in Australian Dollar after conversion int fromAmount; //input amount as an integer bool checkInt = int.TryParse(amount, out fromAmount); //check whole number if (!checkInt) //not whole number { throw new FormatException("Invalid amount"); } switch (code) //check currency code { case "USD": AUD = fromAmount * USDtoAUD; break; case "EUR": if (fromAmount % 5 == 0) //EUR is a multiple of five { AUD = fromAmount * EURtoAUD; } else { throw new FormatException("Euro must be a multiple of 5"); } break; default: //inccorect currency code throw new FormatException("Incorrect currency code"); } return(AUD.ToString("0.00")); //format output to two decimal places }
public void Should_compare_with_null_instance(decimal value) { var instance = new AUD(value); Assert.IsFalse(instance.Equals(null), "Equals"); Assert.AreEqual(1, instance.CompareTo(null), "CompareTo"); }
public void Should_compare_with_another_type_of_instance(decimal value) { var instance1 = new AUD(value); object instance2 = value; Assert.IsFalse(instance1.Equals(instance2), "Equals"); Assert.Throws <ArgumentException>(() => instance1.CompareTo(instance2), "CompareTo"); }
public void Should_cast_to_decimal(decimal value) { var instance = new AUD(value); var actual = (decimal)instance; Assert.AreEqual(value, actual); }
public void Should_cast_from_decimal(decimal value) { var expected = new AUD(value); var actual = (AUD)value; Assert.AreEqual(expected, actual); }
public void Should_throw_exception_on_division_by_zero(decimal value) { var instance = new AUD(value); Assert.Throws <DivideByZeroException>(() => { var unused = instance / 0; }); }
public void Should_roundvalue_withMode(MidpointRounding mode, double value, double expectedValue) { var expected = new AUD((decimal)expectedValue); var instance = new AUD((decimal)value); var actual = instance.Round(mode); Assert.AreEqual(expected, actual); }
public void Should_round_value_withDigit(double value, double expectedValue) { var expected = new AUD((decimal)expectedValue); var instance = new AUD((decimal)value); var actual = instance.Round(1); Assert.AreEqual(expected, actual); }
public void Should_own_a_HashCode(decimal value) { var expected = value.GetHashCode(); var instance = new AUD(value); var actual = instance.GetHashCode(); Assert.AreEqual(expected, actual); }
public void Should_floor_value(double value, double expectedValue) { var expected = new AUD((decimal)expectedValue); var instance = new AUD((decimal)value); var actual = instance.Floor(); Assert.AreEqual(expected, actual); }
public void Should_format_string(string format, string mask) { var expected = string.Format(Consts.CultureEnUS, mask, 1.7578m); var instance = new AUD(1.7578m); var actual = instance.ToString(format, Consts.CultureEnUS); Assert.AreEqual(expected, actual); }
public void Should_divide_instance_by_decimal(double leftValue, double rightValue, double expectedValue) { var expected = new AUD((decimal)expectedValue); var instance = new AUD((decimal)leftValue); var actual = instance / (decimal)rightValue; Assert.AreEqual(expected, actual); }
public void Should_convert_to_string(decimal value) { var expected = $"A$ {value:0.00}"; var instance = new AUD(value); var actual = instance.ToString(); Assert.AreEqual(expected, actual); }
public void Should_multiply_decimal_by_instance(double leftValue, double rightValue, double expectedValue) { var expected = new AUD((decimal)expectedValue); var instance = new AUD((decimal)rightValue); var actual = (decimal)leftValue * instance; Assert.AreEqual(expected, actual); }
public void Should_subtract_two_instances(double leftValue, double rightValue, double expectedValue) { var expected = new AUD((decimal)expectedValue); var leftInstance = new AUD((decimal)leftValue); var rightInstance = new AUD((decimal)rightValue); var actual = leftInstance - rightInstance; Assert.AreEqual(expected, actual); }
public void Should_compare_with_same_value(decimal value) { var baseInstance = new AUD(value); var otherInstance = new AUD(value); Assert.IsTrue(baseInstance.Equals(otherInstance), "Equals"); Assert.IsTrue(baseInstance.Equals((object)otherInstance), "Equals object"); Assert.IsTrue(baseInstance == otherInstance, "=="); Assert.IsFalse(baseInstance != otherInstance, "!="); Assert.AreEqual(0, baseInstance.CompareTo(otherInstance), "CompareTo"); Assert.AreEqual(0, baseInstance.CompareTo((object)otherInstance), "CompareTo object"); Assert.IsFalse(baseInstance < otherInstance, "<"); Assert.IsFalse(baseInstance > otherInstance, ">"); Assert.IsTrue(baseInstance <= otherInstance, "<="); Assert.IsTrue(baseInstance >= otherInstance, ">="); }
public void Should_compare_with_smaller_value(double baseValue, double smallerValue) { var baseInstance = new AUD((decimal)baseValue); var smallerInstance = new AUD((decimal)smallerValue); Assert.IsFalse(baseInstance.Equals(smallerInstance), "Equals"); Assert.IsFalse(baseInstance.Equals((object)smallerInstance), "Equals object"); Assert.IsFalse(baseInstance == smallerInstance, "=="); Assert.IsTrue(baseInstance != smallerInstance, "!="); Assert.AreEqual(+1, baseInstance.CompareTo(smallerInstance), "CompareTo"); Assert.AreEqual(+1, baseInstance.CompareTo((object)smallerInstance), "CompareTo object"); Assert.IsFalse(baseInstance < smallerInstance, "<"); Assert.IsTrue(baseInstance > smallerInstance, ">"); Assert.IsFalse(baseInstance <= smallerInstance, "<="); Assert.IsTrue(baseInstance >= smallerInstance, ">="); }
public void Should_compare_with_bigger_value(double baseValue, double biggerValue) { var baseInstance = new AUD((decimal)baseValue); var biggerInstance = new AUD((decimal)biggerValue); Assert.IsFalse(baseInstance.Equals(biggerInstance), "Equals"); Assert.IsFalse(baseInstance.Equals((object)biggerInstance), "Equals object"); Assert.IsFalse(baseInstance == biggerInstance, "=="); Assert.IsTrue(baseInstance != biggerInstance, "!="); Assert.AreEqual(-1, baseInstance.CompareTo(biggerInstance), "CompareTo"); Assert.AreEqual(-1, baseInstance.CompareTo((object)biggerInstance), "CompareTo object"); Assert.IsTrue(baseInstance < biggerInstance, "<"); Assert.IsFalse(baseInstance > biggerInstance, ">"); Assert.IsTrue(baseInstance <= biggerInstance, "<="); Assert.IsFalse(baseInstance >= biggerInstance, ">="); }
public string convert(string code, string amount) { decimal AUD; //output amount in Australian Dollar after conversion decimal fee; //output of conversio fee int fromAmount; //input amount as an integer if (String.IsNullOrEmpty(code) || String.IsNullOrEmpty(amount)) { throw new FormatException("Missing Input"); } bool checkInt = int.TryParse(amount, out fromAmount); //check whole number if (!checkInt) //not whole number { throw new ArithmeticException("Invalid amount"); } int.TryParse(amount, out fromAmount); if (fromAmount < 1) //not whole number { throw new ArithmeticException("Invalid amount - must be greater than 0"); } switch (code) //check currency code { case "USD": AUD = fromAmount * USDtoAUD; break; case "YEN": AUD = fromAmount * YENtoAUD; break; case "EUR": if (fromAmount % 5 == 0) //EUR is a multiple of five { AUD = fromAmount * EURtoAUD; } else { throw new ArithmeticException("Euro must be a multiple of 5"); } break; default: //inccorect currency code throw new FormatException("Incorrect currency code"); } if (AUD < 1000) { fee = AUD * feeLess1000; } else { fee = AUD * feeMore1000; } AUD = AUD - fee; return(AUD.ToString("0.00")); //format output to two decimal places }
public void SyncState(Serializer ser) { ser.BeginSection(nameof(TIA)); _ball.SyncState(ser); _hmove.SyncState(ser); ser.Sync("hsyncCnt", ref _hsyncCnt); // add everything to the state ser.Sync("Bus_State", ref BusState); ser.Sync("_ctrlPFDelay", ref _ctrlPFDelay); ser.Sync("_ctrlPFVal", ref _ctrlPFVal); ser.Sync("PF0_up", ref _pf0Update); ser.Sync("PF1_up", ref _pf1Update); ser.Sync("PF2_up", ref _pf2Update); ser.Sync("PF0_upper", ref _pf0Updater); ser.Sync("PF1_upper", ref _pf1Updater); ser.Sync("PF2_upper", ref _pf2Updater); ser.Sync("PF0_delay", ref _pf0DelayClock); ser.Sync("PF1_delay", ref _pf1DelayClock); ser.Sync("PF2_delay", ref _pf2DelayClock); ser.Sync("PF0_max", ref _pf0MaxDelay); ser.Sync("PF1_max", ref _pf1MaxDelay); ser.Sync("PF2_max", ref _pf2MaxDelay); ser.Sync("Enam0_delay", ref _enam0Delay); ser.Sync("Enam1_delay", ref _enam1Delay); ser.Sync("Enab_delay", ref _enambDelay); ser.Sync("Enam0_val", ref _enam0Val); ser.Sync("Enam1_val", ref _enam1Val); ser.Sync("Enab_val", ref _enambVal); ser.Sync("P0_stuff", ref _p0Stuff); ser.Sync("P1_stuff", ref _p1Stuff); ser.Sync("M0_stuff", ref _m0Stuff); ser.Sync("M1_stuf", ref _m1Stuff); ser.Sync("b_stuff", ref _bStuff); ser.Sync("_hmp0_no_tick", ref _hmp0_no_tick); ser.Sync("_hmp1_no_tick", ref _hmp1_no_tick); ser.Sync("_hmm0_no_tick", ref _hmm0_no_tick); ser.Sync("_hmm1_no_tick", ref _hmm1_no_tick); ser.Sync("_hmb_no_tick", ref _hmb_no_tick); ser.Sync("hmp0_delay", ref _hmp0Delay); ser.Sync("hmp0_val", ref _hmp0Val); ser.Sync("hmp1_delay", ref _hmp1Delay); ser.Sync("hmp1_val", ref _hmp1Val); ser.Sync("hmm0_delay", ref _hmm0Delay); ser.Sync("hmm0_val", ref _hmm0Val); ser.Sync("hmm1_delay", ref _hmm1Delay); ser.Sync("hmm1_val", ref _hmm1Val); ser.Sync("hmb_delay", ref _hmbDelay); ser.Sync("hmb_val", ref _hmbVal); ser.Sync("_nusiz0Delay", ref _nusiz0Delay); ser.Sync("_nusiz0Val", ref _nusiz0Val); ser.Sync("_nusiz1Delay", ref _nusiz1Delay); ser.Sync("_nusiz1Val", ref _nusiz1Val); ser.Sync("_hmClrDelay", ref _hmClrDelay); ser.Sync("PRG0_delay", ref _prg0Delay); ser.Sync("PRG1_delay", ref _prg1Delay); ser.Sync("PRG0_val", ref _prg0Val); ser.Sync("PRG1_val", ref _prg1Val); ser.Sync("Ticks", ref _doTicks); ser.Sync(nameof(hmove_cnt_up), ref hmove_cnt_up); ser.Sync("VBlankDelay", ref _vblankDelay); ser.Sync("VBlankValue", ref _vblankValue); // some of these things weren't in the state because they weren't needed if // states were always taken at frame boundaries ser.Sync("capChargeStart", ref _capChargeStart); ser.Sync("capCharging", ref _capCharging); ser.Sync("vblankEnabled", ref _vblankEnabled); ser.Sync("vsyncEnabled", ref _vsyncEnabled); ser.Sync("CurrentScanLine", ref _currentScanLine); ser.Sync(nameof(AudioClocks), ref AudioClocks); ser.Sync(nameof(New_Frame), ref New_Frame); ser.BeginSection("Audio"); AUD.SyncState(ser); ser.EndSection(); ser.BeginSection("Player0"); _player0.SyncState(ser); ser.EndSection(); ser.BeginSection("Player1"); _player1.SyncState(ser); ser.EndSection(); _playField.SyncState(ser); ser.EndSection(); }
public void Should_have_a_symbol(decimal value) { ICurrency actual = new AUD(value); Assert.AreEqual(AUD.Symbol, actual.Symbol); }