public float ProcessStatement(IContext _context, string statement) { string[] split = statement.Split(' '); string[] creditsSplit = statement.Split(new string[] { " is " }, StringSplitOptions.None); string[] galacticUnits = creditsSplit[0].Trim().Split(' '); StringBuilder sb = new StringBuilder(); for (int i = 0; i < galacticUnits.Length - 1; i++) { sb.Append(_context.GetVariable(galacticUnits[i]).Value); } int count = new GalacticUnit(sb.ToString()).ToArabic(); string key = galacticUnits[galacticUnits.Length - 1]; //Check if the key is already in variables list if (_context.IsVariableExists(key)) { throw new QueryGalaxyException("The variable name cannot be used", statement, key, null); } string[] creditUnits = creditsSplit[1].Trim().Split(' '); int totalCredits = int.Parse(creditUnits[0]); float oneCredit = ((float)totalCredits / (float)count); _context.AddCredit(key, oneCredit); return(oneCredit); }
public void ZeroArabicTest() { GalacticUnit gu = new GalacticUnit(); int arabicVal = gu.ToArabic(); Assert.AreEqual <int>(arabicVal, 0); }
public void ArabicTest() { GalacticUnit gu = new GalacticUnit("MCMXLIV"); int arabicVal = gu.ToArabic(); Assert.AreEqual <int>(arabicVal, 1944); }
public void BoundaryArabicTest() { GalacticUnit gu = new GalacticUnit("MMMCMXCIX"); int arabicVal = gu.ToArabic(); Assert.AreEqual <int>(arabicVal, 3999); }
public void SubtractionTest() { GalacticUnit a = new GalacticUnit("X"); //10 GalacticUnit b = new GalacticUnit("V"); //5 GalacticUnit gu = a - b; Assert.AreEqual <long>(gu.ToArabic(), 5); Assert.AreEqual <string>(gu.Value, "V"); }
public void DivisionTest() { GalacticUnit a = new GalacticUnit("X"); //10 GalacticUnit b = new GalacticUnit("V"); //5 GalacticUnit gu = a / b; Assert.AreEqual <long>(gu.ToArabic(), 2); Assert.AreEqual <string>(gu.Value, "II"); }
public void MultiplicationTest() { GalacticUnit a = new GalacticUnit("X"); //10 GalacticUnit b = new GalacticUnit("V"); //5 GalacticUnit gu = a * b; Assert.AreEqual <long>(gu.ToArabic(), 50); Assert.AreEqual <string>(gu.Value, "L"); }
public float ProcessStatement(IContext _context, string statement) { string[] split = statement.Split(' '); GalacticUnit gu = new GalacticUnit(split[2]); _context.AddVariable(split[0], gu); return(gu.ToArabic()); }
public float ProcessStatement(IContext _context, string statement) { string[] calculationSplit = statement.Split(new string[] { " is " }, StringSplitOptions.None); string[] tokens = calculationSplit[1].Split(' ', '?'); StringBuilder sb = new StringBuilder(); foreach (var t in tokens) { if (string.IsNullOrWhiteSpace(t)) { continue; } sb.Append(_context.GetVariable(t).Value); } GalacticUnit galacticUnit = new GalacticUnit(sb.ToString()); return(galacticUnit.ToArabic()); }
public float ProcessStatement(IContext _context, string statement) { string[] split = statement.Split(' '); string[] calculationSplit = statement.Split(new string[] { " is " }, StringSplitOptions.None); string[] tokens = calculationSplit[1].Split(' ', '?'); //Remove any null variable List <string> validTokens = new List <string>(); foreach (var v in tokens) { if (!string.IsNullOrWhiteSpace(v)) { validTokens.Add(v); } } tokens = validTokens.ToArray(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < tokens.Length - 1; i++) { sb.Append(_context.GetVariable(tokens[i]).Value); } int count = new GalacticUnit(sb.ToString()).ToArabic(); string key = tokens[tokens.Length - 1]; if (!_context.IsCreditExists(key)) { throw new QueryGalaxyException("The credit variable is not valid", statement, key, null); } float total = _context.GetCredit(key) * count; return(total); }
public void ToGalactivBoundaryTest() { GalacticUnit gu = new GalacticUnit(3999); Assert.AreEqual <string>(gu.Value, "MMMCMXCIX"); }
public void ToGalactivTest() { GalacticUnit gu = new GalacticUnit(1944); Assert.AreEqual <string>(gu.Value, "MCMXLIV"); }
public void GreaterThanFourThousandTest() { GalacticUnit gu = new GalacticUnit(4500); }
public void InValidTest() { GalacticUnit gu = new GalacticUnit("lsakdjf"); }
public void ValidTest() { GalacticUnit gu = new GalacticUnit("XXLV"); Assert.IsFalse(string.IsNullOrEmpty(gu.Value)); }
public void EmptyTest() { GalacticUnit gu = new GalacticUnit(); Assert.IsTrue(string.IsNullOrEmpty(gu.Value)); }