protected override TimeSpan GetTimeLimit(Shomon shomon)
 {
     if (ShomonInputMethod.Card == shomon.InputMethod)
     {
         var mondaiWordsArray = shomon.正解探索();
         if (mondaiWordsArray.Any(x => null == x))
         {
             var message = string.Format("正解の組み合わせが見つかりません: id: " + shomon.Id);
             throw new MondaiDocumentException(message);
         }
         try
         {
             var a = mondaiWordsArray.Select(x => x.Count()).Average();
             var b = CountLetters(shomon.Mondaibun) * 0.125d;
             return TimeSpan.FromSeconds(Math.Max(a, b));
         }
         catch
         {
             Trace.WriteLine("id: " + shomon.Id);
             throw;
         }
     }
     else if (ShomonInputMethod.Typing == shomon.InputMethod)
     {
         var average = shomon.CorrectAnswers.Select(x => x.Text.Count()).Average();
         return TimeSpan.FromMinutes(average / (KeystrokesPerMinute / 2d));
     }
     else
     {
         throw new ApplicationException("never reach here.");
     }
 }
        public static Shomon CreateShomon(EmpElement shomonElement)
        {
            var shomon = new Shomon()
            {
                Id = shomonElement.GetValue("id"),
                Mondaibun = shomonElement.GetValue("mon"),
            };
            var seikaiTexts = shomonElement.GetValues("sei").Select(x => 余分な空白を取り除く(x));
            if (seikaiTexts.Any(x => string.IsNullOrWhiteSpace(x))) throw new EmpException("seiが指定されていません。: id :" + shomon.Id);

            var display = shomonElement.GetValue("display");
            if (!string.IsNullOrWhiteSpace(display))
            {
                shomon.LettersThatAreDisplayedOnCard = (LettersThatAreDisplayedOnCard)Enum.Parse(typeof(LettersThatAreDisplayedOnCard), display, true);
            }

            // 正解項目の設定
            foreach (var seikaiText in seikaiTexts.Select(text => MondaiWord.分割指示記号を取り除く(text)))
            {
                shomon.CorrectAnswers.Add(new CorrectAnswer(seikaiText));
            }

            var wordTexts = shomonElement.GetValues("word").Select(x => 余分な空白を取り除く(x));
            shomon.MondaiWords = wordTexts.Select(s => new MondaiWord(s)).ToArray();

            // word項目で正解が組み立てられない場合は、正解項目を分割処理してword項目を作成する。
            var result = shomon.正解探索();
            if (result.Any(array => null == array))
            {
                var otoriTexts = shomonElement.GetValues("otori").Concat(shomonElement.GetValues("otr")).Select(x => 余分な空白を取り除く(x));
                var texts = seikaiTexts.Concat(otoriTexts);
                shomon.MondaiWords = MondaiWord.Split2(texts).Concat(shomon.MondaiWords).ToArray();
            }
            /*
            #if DEBUG
            if (Environment.StackTrace.Contains("括弧とクォーテーションに対応させる"))
            {
                foreach (var mondaiWord in shomon.MondaiWords)
                {
                    Console.WriteLine(mondaiWord);
                }
            }
            #endif // DEBUG
            */
            if (shomon.正解探索().Any(array => null == array))
            {
                throw new ApplicationException(string.Format("正解の組み合わせが見つかりません。: id: {0}", shomon.Id));
            }
            return shomon;
        }
        public void Xmlとの相互変換テストでピリオドと前の単語が結合されていない不具合()
        {
            using (var tempFile1 = new TempFile())
            using (var tempFile2 = new TempFile())
            {
                FileUtility.Save(tempFile1.Value, _test91);
                var mondaiDocument = MondaiDocument.Load(tempFile1.Value);
                Assert.AreEqual("mondaiDocument1", mondaiDocument.Id);

                var emp = EmpElement.Create(mondaiDocument);
                var shomonElement = emp.GetAllItems().First(x => "shomon" == x.Name);
                Assert.AreEqual("3-2-1", shomonElement.GetValue("id"));
                Assert.AreEqual("[英訳] これはボールです。", shomonElement.GetValue("mon"));
                Assert.AreEqual("This+is a+ball+.", shomonElement.GetValue("sei"));

                CollectionAssert.IsEmpty(shomonElement.GetValues("word").Select(s => new MondaiWord(s)));

                {
                    var seikaiTexts = shomonElement.GetValues("sei");

                    CollectionAssert.AreEqual(new []
                    {
                        "This+is a+ball+.",
                    }, seikaiTexts);

                    CollectionAssert.AreEqual(new []
                    {
                        new MondaiWord("This is"),
                        new MondaiWord("a ball."),

                    }, MondaiWord.Split2(seikaiTexts));
                }
                {
                    var shomon = new Shomon();
                    shomon.CorrectAnswers.Add(new CorrectAnswer("This is a ball."));

                    shomon.MondaiWords = new []
                    {
                        new MondaiWord("This is"),
                        new MondaiWord("a ball."),
                    };
                    var result = shomon.正解探索();
                    Assert.AreEqual(1, result.Count());

                    CollectionAssert.AreEqual
                    (
                        shomon.MondaiWords,
                        result[0]
                    );
                }
                {
                    var shomon = EmpElement.CreateShomon(shomonElement);
                    Assert.AreEqual("3-2-1", shomon.Id);

                    mondaiDocument = emp.GetMondaiDocument();
                    mondaiDocument.Save(tempFile2.Value);
            //				TestUtility.ShowFile(tempFile2.Name);
            //				Assert.AreEqual(FileUtility.Load(tempFile1.Name), FileUtility.Load(tempFile2.Name));
                    FileAssert.AreEqual(tempFile1.Value, tempFile2.Value);
                }
            }
        }