public void SelectQuestionsWithNumberTest() { GeneratePaperTemplate_Accessor target = new GeneratePaperTemplate_Accessor(); List<AutoRatio> ratios; int totalNumber; List<Question> qs; Object expected, actual; actual = null; #region 无备选试题 ratios = new List<AutoRatio>(); ratios.Add(new AutoRatio("单选题", 0.2)); ratios.Add(new AutoRatio("多选题", 0.2)); ratios.Add(new AutoRatio("判断题", 0.2)); ratios.Add(new AutoRatio("公文改错题", 0.1)); ratios.Add(new AutoRatio("计算题", 0.1)); ratios.Add(new AutoRatio("案例分析题", 0.1)); ratios.Add(new AutoRatio("问答题", 0.1)); totalNumber = 100; qs = new List<Question>(); expected = "“单选题”没有备选试题。"; try { target.SelectQuestionsWithNumber(ratios, totalNumber, qs); } catch (Exception ex) { actual = ex; } Assert.AreEqual(expected, ((Exception)actual).Message); actual = null; #endregion #region 备选试题数量不足 ratios = new List<AutoRatio>(); ratios.Add(new AutoRatio("单选题", 0.2)); ratios.Add(new AutoRatio("多选题", 0.2)); ratios.Add(new AutoRatio("判断题", 0.2)); ratios.Add(new AutoRatio("公文改错题", 0.1)); ratios.Add(new AutoRatio("计算题", 0.1)); ratios.Add(new AutoRatio("案例分析题", 0.1)); ratios.Add(new AutoRatio("问答题", 0.1)); totalNumber = 100; qs = olsEni.Questions.Where(m => m.Q_Type == "单选题" && m.Q_Status == (Byte)Status.Available).Take(1).ToList(); expected = "“单选题”备选试题总数小于类型总数。"; try { target.SelectQuestionsWithNumber(ratios, totalNumber, qs); } catch (Exception ex) { actual = ex; } Assert.AreEqual(expected, ((Exception)actual).Message); Debug.WriteLine(((Exception)actual).Data["Info"]); Debug.WriteLine("------------------------------"); actual = null; #endregion #region [已注释]超过指定重复次数 /*ratios = new List<AutoRatio>(); ratios.Add(new AutoRatio("单选题", 0.2)); ratios.Add(new AutoRatio("多选题", 0.2)); ratios.Add(new AutoRatio("判断题", 0.2)); ratios.Add(new AutoRatio("公文改错题", 0.1)); ratios.Add(new AutoRatio("计算题", 0.1)); ratios.Add(new AutoRatio("案例分析题", 0.1)); ratios.Add(new AutoRatio("问答题", 0.1)); totalNumber = 100; qs = olsEni.Questions.Where(m => m.Q_Type == "单选题" && m.Q_Status == (Byte)Status.Available).Take(1).ToList(); expected = "随机选取试题失败。"; try { target.SelectQuestionsWithNumber(ratios, totalNumber, qs); } catch (Exception ex) { actual = ex; } Assert.AreEqual(expected, ((Exception)actual).Message); Debug.WriteLine(((Exception)actual).Data["Info"]); actual = null;*/ #endregion #region 数量不足时,补足 ratios = new List<AutoRatio>(); ratios.Add(new AutoRatio("单选题", 0.2)); ratios.Add(new AutoRatio("多选题", 0.2)); ratios.Add(new AutoRatio("判断题", 0.2)); //ratios.Add(new AutoRatio("公文改错题", 0.1)); //ratios.Add(new AutoRatio("计算题", 0.1)); //ratios.Add(new AutoRatio("案例分析题", 0.1)); //ratios.Add(new AutoRatio("问答题", 0.1)); ratios = target.AdjustRatios(ratios); totalNumber = 10; qs = olsEni.Questions.Where(m => m.Q_Status == (Byte)Status.Available).ToList(); expected = totalNumber; actual = target.SelectQuestionsWithNumber(ratios, totalNumber, qs); Assert.AreEqual(expected, ((List<Question>)actual).Count); Debug.WriteLine("Question Type:"); foreach (var q in ((List<Question>)actual)) { Debug.WriteLine(" " + q.Q_Type); } Debug.WriteLine("------------------------------"); actual = null; #endregion }
public void AdjustRatiosTest() { Object expected, actual; GeneratePaperTemplate_Accessor target = new GeneratePaperTemplate_Accessor(); List<AutoRatio> ratios; // 正常情况 ratios = new List<AutoRatio>(); ratios.Add(new AutoRatio("单选题", 0.2)); ratios.Add(new AutoRatio("多选题", 0.2)); ratios.Add(new AutoRatio("判断题", 0.2)); ratios.Add(new AutoRatio("公文改错题", 0.1)); ratios.Add(new AutoRatio("计算题", 0.1)); ratios.Add(new AutoRatio("案例分析题", 0.1)); ratios.Add(new AutoRatio("问答题", 0.1)); expected = ratios.Sum(m => m.percent); actual = target.AdjustRatios(ratios).Sum(m => m.percent); Assert.AreEqual(expected, actual); actual = null; // 未设置出题比例 ratios = new List<AutoRatio>(); expected = "未设置出题比例。"; try { target.AdjustRatios(ratios); } catch (Exception ex) { actual = ex; } Assert.AreEqual(expected, ((Exception)actual).Message); actual = null; // 出题比例小于 50% ratios = new List<AutoRatio>(); ratios.Add(new AutoRatio("单选题", 0)); ratios.Add(new AutoRatio("多选题", 0)); ratios.Add(new AutoRatio("判断题", 0)); ratios.Add(new AutoRatio("公文改错题", 0.1)); ratios.Add(new AutoRatio("计算题", 0.1)); ratios.Add(new AutoRatio("案例分析题", 0.1)); ratios.Add(new AutoRatio("问答题", 0.1)); expected = "出题比例小于 50% 。"; try { target.AdjustRatios(ratios); } catch (Exception ex) { actual = ex; } Assert.AreEqual(expected, ((Exception)actual).Message); actual = null; // 出题比例大于 100% ratios = new List<AutoRatio>(); ratios.Add(new AutoRatio("单选题", 0.3)); ratios.Add(new AutoRatio("多选题", 0.2)); ratios.Add(new AutoRatio("判断题", 0.2)); ratios.Add(new AutoRatio("公文改错题", 0.1)); ratios.Add(new AutoRatio("计算题", 0.1)); ratios.Add(new AutoRatio("案例分析题", 0.1)); ratios.Add(new AutoRatio("问答题", 0.1)); expected = "出题比例大于 100% 。"; try { target.AdjustRatios(ratios); } catch (Exception ex) { actual = ex; } Assert.AreEqual(expected, ((Exception)actual).Message); actual = null; // 自动补缺 ratios = new List<AutoRatio>(); ratios.Add(new AutoRatio("单选题", 0)); ratios.Add(new AutoRatio("多选题", 0)); ratios.Add(new AutoRatio("判断题", 0)); ratios.Add(new AutoRatio("公文改错题", 0)); ratios.Add(new AutoRatio("计算题", 0.2)); ratios.Add(new AutoRatio("案例分析题", 0.2)); ratios.Add(new AutoRatio("问答题", 0.2)); expected = 0.34; actual = target.AdjustRatios(ratios); Assert.AreEqual(expected, (Double)((List<AutoRatio>)actual)[((List<AutoRatio>)actual).Count - 1].percent); actual = null; }