Exemple #1
0
    public void DigitValueTest(int places, int value, int place, int expected)
    {
        var dg = new DigitGroup(places);

        dg.SetValue(value);
        Assert.That(dg.GetDigitValue(place), Is.EqualTo(expected));
    }
Exemple #2
0
    public void DigitGroupUsedTest(int places, int value, int place, bool used)
    {
        var dg = new DigitGroup(places);

        dg.SetValue(value);
        Assert.That(dg.IsDigitUsed(place) == used);
    }
        private IEnumerable <string> BuildWholeNumberText(decimal wholeNumber)
        {
            if (wholeNumber > 0)
            {
                // convert 1234 to ["432", "1"]
                var wholeNumberGroups = wholeNumber.ToString("#,#").Split(",").ToList();
                wholeNumberGroups.Reverse();

                // convert to [{ Item1: "432", Item2: "", { Item1: "1", Item2: "thousand" }]
                var groupNames  = new[] { "", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion", "septillion", "octillion" };
                var digitGroups = wholeNumberGroups.Zip(groupNames, (WholeNumberGroup, GroupName) => (WholeNumberGroup, GroupName)).ToList();

                // put back into the order the digit groups should be written
                digitGroups.Reverse();

                foreach (var digitGroup in digitGroups)
                {
                    // discard any digit groups that should not be written to avoid e.g. "zero thousand"
                    if (System.Convert.ToInt32(digitGroup.Item1) != 0)
                    {
                        var text = new DigitGroup(System.Convert.ToInt32(digitGroup.WholeNumberGroup), digitGroup.GroupName).ToString();
                        if (!string.IsNullOrEmpty(text))
                        {
                            yield return(text);
                        }
                    }
                }
            }
        }
Exemple #4
0
    public void DigitGroupDigitsTest(int places, int value, int[] expectedDigits)
    {
        var dg = new DigitGroup(places);

        dg.SetValue(value);
        Assert.That(dg.Digits, Is.EqualTo(expectedDigits));
    }
 public void DigitGroupTestsRunner()
 {
     foreach (var expectation in DigitGroupTests.expectations)
     {
         var group = new DigitGroup(expectation.Number, expectation.NumberIndex);
         Assert.AreEqual(group.ToString(), expectation.ExpectedString);
     }
 }
		public void TestMethod()
		{
			DigitGroup dg = new DigitGroup();
			dg.Add(1);
			dg.Add(3);
			dg.Add(1);
			dg.Add(1);
			Assert.AreEqual(9, dg.MinLength, "DigitGroup's property MinLength works wrong");
		}
Exemple #7
0
		public static long CountOfStates(int cellsCount, DigitGroup digits)
		{
			checked{
				long result = 0;
				int barsCount = digits.Count; // n
				int freeCellsCount = cellsCount - digits.MinLength - barsCount + 1; // N1 = N - H - n + 1
				
				return result;
			}
		}
Exemple #8
0
		public void RebuildDigitGroupCollectionsFromMap() {
			leftCollection = new LeftDigitGroupCollection(Height);
			DigitGroup digitGroup = null;
			int currentBarLength = 0;
			for (int i = 0; i < Height; i++) {
				Cell[] row = map.GetRow(i);
				digitGroup = new DigitGroup();
				for(int j = 0; j < Width; j++) {
					switch(row[j].State) {
						case CellStateEnum.Filled:
							currentBarLength++;
							break;
						case CellStateEnum.Normal:
						case CellStateEnum.Space:
							if(currentBarLength > 0) {
								digitGroup.Add(currentBarLength);
							}
							currentBarLength = 0;
							break;
					}
					if(j == Width - 1 && currentBarLength > 0) {
						digitGroup.Add(currentBarLength);
						currentBarLength = 0;
					}
				}
				leftCollection.Add(digitGroup);
			}
			
			topCollection = new TopDigitGroupCollection(Width);
			currentBarLength = 0;
			for (int i = 0; i < Width; i++) {
				Cell[] column = map.GetColumn(i);
				digitGroup = new DigitGroup();
				for(int j = 0; j < Height; j++) {
					switch(column[j].State) {
						case CellStateEnum.Filled:
							currentBarLength++;
							break;
						case CellStateEnum.Normal:
						case CellStateEnum.Space:
							if(currentBarLength > 0) {
								digitGroup.Add(currentBarLength);
							}
							currentBarLength = 0;
							break;
					}
					if(j == Height - 1 && currentBarLength > 0) {
						digitGroup.Add(currentBarLength);
						currentBarLength = 0;
					}
				}
				topCollection.Add(digitGroup);
			}
		}
        private void MenuItemFileDigitGrouping_Click(object sender, RoutedEventArgs e)
        {
            double afisare;
            string zecimal    = "0";
            int    indexpoint = resultText.IndexOf('.');

            if (indexpoint != -1)
            {
                zecimal = resultText.Substring(indexpoint + 1);
            }
            if (culture == DigitGroup.ROM)
            {
                culture    = DigitGroup.ENG;
                afisare    = Convert.ToDouble(resultText.Replace(_decimalDelimiter, "."), _invariantNF);
                Entry.Text = afisare.ToString(afisare % 1 == 0 ? "N0" : "N" + zecimal.Length, new CultureInfo("ro-RO"));
            }
            else if (culture == DigitGroup.ENG)
            {
                culture    = DigitGroup.ROM;
                afisare    = Convert.ToDouble(resultText.Replace(_decimalDelimiter, "."), _invariantNF);
                Entry.Text = afisare.ToString(afisare % 1 == 0 ? "N0" : "N" + zecimal.Length, new CultureInfo("en-US"));
            }
        }
 private static string getName(int idx, Language language, DigitGroup group)
 {
     return(_numberWords.First(x => x.Group == group && x.Language == language).Names.ElementAt(idx));
 }
Exemple #11
0
        // Private Methods (2) 

        private static string getName(int idx, Language language, DigitGroup group)
        {
            return(NumberWords.Where(x => x.Group == group && x.Language == language).First().Names[idx]);
        }
Exemple #12
0
        private string GetDigitText(DigitGroup group, int key)
        {
            var digit = _digitTexts.SingleOrDefault(v => v.Group == group && v.Key == key)?.Text;

            return(digit);
        }
        private string GetDecimalsText(decimal decimals)
        {
            var cents = new DigitGroup(System.Convert.ToInt32(decimals), "cent").ToString();

            return(decimals == 1 ? cents : $"{cents}s");
        }
 // Private Methods (2)
 private static string getName(int idx, Language language, DigitGroup group)
 {
     return _numberWords.First(x => x.Group == @group && x.Language == language).Names[idx];
 }
Exemple #15
0
		public static int MinLength(DigitGroup dg)
		{
			return 0;
		}
Exemple #16
0
    public void DigitGroupMaxValueTest(int places, int expectedValue)
    {
        var dg = new DigitGroup(places);

        Assert.That(dg.MaxValue, Is.EqualTo(expectedValue));
    }
        public string GetText(DigitGroup group, int key)
        {
            var digit = _digitTexts.SingleOrDefault(text => text.Group == group && text.Key == key)?.Text;

            return(digit);
        }