Beispiel #1
0
 //get statistic from category and records
 public Statistic GetStatistic(Category category, bool isPositive)
 {
     Statistic statistic = new Statistic(category);
     foreach (Record record in _recordModel.Records)
     {
         if (record.Category.Equals(category) && ((isPositive && record.Amount >= 0) || (!isPositive && record.Amount < 0)))
         {
             statistic.Count++;
             statistic.Amounts += record.Amount;
         }
     }
     return statistic;
 }
 public void TestSetPercent()
 {
     const String SEVENTY_FIVE_PERCENT = "75%";
     const String TWENTY_FIVE_PERCENT = "25%";
     CategoryModel categoryModel = new CategoryModel(); // TODO: 初始化為適當值
     Category categoryMovie = new Category(CATEGORY_NAME_MOVIE);
     Category categoryEntertainment = new Category(CATEGORY_NAME_ENTERTAINMENT);
     categoryModel.AddCategory(categoryMovie);
     categoryModel.AddCategory(categoryEntertainment);
     RecordModel recordModel = new RecordModel(categoryModel); // TODO: 初始化為適當值
     StatisticModel statisticModel = new StatisticModel(categoryModel, recordModel); // TODO: 初始化為適當值
     BindingList<Statistic> statistics = new BindingList<Statistic>(); // TODO: 初始化為適當值
     Statistic statisticMovie = new Statistic(categoryMovie);
     Statistic statisticEntertainment = new Statistic(categoryEntertainment);
     statisticMovie.Amounts = 1000;
     statistics.Add(statisticMovie);
     statisticEntertainment.Amounts = 3000;
     statistics.Add(statisticEntertainment);
     int amounts = 4000; // TODO: 初始化為適當值
     statisticModel.SetPercent(statistics, amounts);
     Assert.AreEqual(TWENTY_FIVE_PERCENT, statisticMovie.Percent);
     Assert.AreEqual(SEVENTY_FIVE_PERCENT, statisticEntertainment.Percent);
 }