コード例 #1
0
        public void decoyの別名dを追加()
        {
            var text = @"
            version = 1.1
            document
            {
            id = document0
            title =

            daimon
            {
            id = daimon0
            title =

            chumon
            {
            id = chumon0
            title =
            shuffle = true
            helpId =
            helpId =

            shomon
            {
                id = shomon0
                q = aaa
                c = This is a ball.
                d = apple (an apple)
            }
            }
            }
            }";

            using (var tempFile = new TempFile(text))
            {
                var accessor = new EmpDocumentAccessor1_1();
                var mondaiDocument = accessor.Load(tempFile.Name);

            //				var element = EmpDocument.Load(tempFile.Name);
            //				var mondaiDocument = element.GetMondaiDocument();

                var shomon = (Shomon)mondaiDocument.GetItem("shomon0");
                CollectionAssert.AreEqual(new []
                {
                    new MondaiWord("This"),
                    new MondaiWord("is"),
                    new MondaiWord("a"),
                    new MondaiWord("ball"),
                    new MondaiWord("."),
                    new MondaiWord("apple"),
                    new MondaiWord("an apple"),

                }, shomon.MondaiWords);
            }
        }
コード例 #2
0
        public void コロンに対応させる()
        {
            // They need two kind of support: economic and technical.
            var text = @"
            version = 1.1
            document
            {
            id = document0
            title =

            daimon
            {
            id = daimon0
            title =

            chumon
            {
            id = chumon0
            title =
            shuffle = true
            helpId =
            helpId =

            shomon
            {
                id = shomon0
                q = bbb
                c = They need two kind of support: economic and technical.
            }
            }
            }
            }";

            using (var tempFile = new TempFile(text))
            {
                var accessor = new EmpDocumentAccessor1_1();
                var mondaiDocument = accessor.Load(tempFile.Name);

            //				var element = EmpDocument.Load(tempFile.Name);
            //				var mondaiDocument = element.GetMondaiDocument();

                var shomon = (Shomon)mondaiDocument.GetItem("shomon0");
                Assert.AreEqual("bbb", shomon.Mondaibun);
                CollectionAssert.AreEqual(new []
                {
                    new MondaiWord("They"),
                    new MondaiWord("need"),
                    new MondaiWord("two"),
                    new MondaiWord("kind"),
                    new MondaiWord("of"),
                    new MondaiWord("support"),
                    new MondaiWord(":"),
                    new MondaiWord("economic"),
                    new MondaiWord("and"),
                    new MondaiWord("technical"),
                    new MondaiWord("."),
                }, shomon.MondaiWords);
            }
        }
コード例 #3
0
        public void カード分割機能のデータ構造に対応させる()
        {
            var text = @"
            version = 1.1
            document
            {
            id = document0
            title =

            daimon
            {
            id = daimon0
            title =

            chumon
            {
            id = chumon0
            title =
            shuffle = true
            helpId =
            helpId =

            shomon
            {
                id = shomon0
                mon = 何年前に君のおじさんはニューヨークにいたのですか。
                c = a b/c/d e+f
                w = g
                w = h
            }
            shomon
            {
                id = shomon1
                q = aaa
                c = This+is a+ball.
            }
            }
            }
            }";

            using (var tempFile = new TempFile(text))
            {
                var accessor = new EmpDocumentAccessor1_1();
                var mondaiDocument = accessor.Load(tempFile.Name);

                var shomon = (Shomon)mondaiDocument.GetItem("shomon0");
                Assert.AreEqual("a bcd e f", shomon.CorrectAnswers.First().Text);

                CollectionAssert.AreEquivalent(new []
                {
                    new MondaiWord("a"),
                    new MondaiWord("b", false, true),
                    new MondaiWord("c", true, true),
                    new MondaiWord("d", true, false),
                    new MondaiWord("e f"),
                    new MondaiWord("g"),
                    new MondaiWord("h"),

                }, shomon.MondaiWords);
            }
        }
コード例 #4
0
        public void seiに2個以上の空白が含まれていた場合の処理()
        {
            var text = @"
            version = 1.1
            document
            {
            id = document0
            title =

            daimon
            {
            id = daimon0
            title =

            chumon
            {
            id = chumon0
            title =
            shuffle = true
            helpId =
            helpId =

            shomon
            {
                id = shomon0
                q = aaa
                c = This  is a ball.
            }
            }
            }
            }";

            using (var tempFile = new TempFile(text))
            {
                var accessor = new EmpDocumentAccessor1_1();
                var mondaiDocument = accessor.Load(tempFile.Name);

            //				var element = EmpDocument.Load(tempFile.Name);
            //				var shomonElement = element.Body.GetAllItems().First(x => "shomon" == x.Name);
            //				var mondaiDocument = element.GetMondaiDocument();

                var shomon = mondaiDocument.GetAllItems().OfType<Shomon>().First(x => "shomon0" == x.Id);
                Assert.AreEqual("This is a ball.", shomon.CorrectAnswers.First().Text);
                CollectionAssert.AreEqual
                (
                    new []
                    {
                        new MondaiWord("This"),
                        new MondaiWord("is"),
                        new MondaiWord("a"),
                        new MondaiWord("ball"),
                        new MondaiWord("."),
                    },
                    shomon.MondaiWords
                );
            }
        }
コード例 #5
0
        public void seiが指定されなかったとき例外を送出する()
        {
            var text = @"
            version = 1.1
            document
            {
            id = document0
            title =

            daimon
            {
            id = daimon0
            title =

            chumon
            {
            id = chumon0
            title =
            shuffle = true
            helpId =
            helpId =

            shomon
            {
                id = shomon0
                q = aaa
                c = This is a ball.
                c =
                decoy = apple (an apple)
            }
            }
            }
            }";

            using (var tempFile = new TempFile(text))
            {
            /*				var element = EmpDocument.Load(tempFile.Name);
                Assert.Throws<EmpException>(() =>
                {
                    var mondaiDocument = element.GetMondaiDocument();
                });*/

                var accessor = new EmpDocumentAccessor1_1();
                Assert.Throws<EmpException>(() =>
                {
                    accessor.Load(tempFile.Name);
                });
            }
        }
コード例 #6
0
        public void optionalにtruefalse以外が指定されていたら例外()
        {
            var text =
            @"version = 1.1
            document
            {
            id = document1
            title = documentB

            daimon
            {
            id = id1
            title = ""daimonTitle""

            chumon
            {
            id = chumon2-2
            title = ""chumonTitle""

            shuffle = aaa

            shomon
            {
                id = shomon3
                q
                {
                    Are these cameras?
                }

                c
                {
                    No, they aren't.
                }

                w
                {
                    Yes,
                }
                w
                {
                    they are.
                }
            }
            }
            }
            }
            ";

            using (var tempFile = new TempFile(text))
            {
                var accessor = new EmpDocumentAccessor1_1();
                Assert.Throws<EmpException>(() =>
                {
                    accessor.Load(tempFile.Name);
                });

            /*				var emp = EmpDocument.Load(tempFile.Name);
                Assert.Throws<EmpException>(() =>
                {
                    emp.GetMondaiDocument();
                });*/
            }
        }
コード例 #7
0
        public void LoadingTest()
        {
            var text =
            @"version = 1.1
            document
            {
            id = document1
            title = Document Title 1

            daimon
            {
            id = daimon1
            title = ""Daimon Title 1""

            chumon
            {
            id = chumon1
            title = ""Chumon Title 1""

            shomon
            {
                id = shomon1
                question = Are these cameras?
                correct = No, they aren't.
                words = Yes,
                words = they are.
            }
            }
            chumon
            {
            id = chumon2
            title = ""Chumon Title 2""

            shomon
            {
                id = shomon2
                q = Are these cameras?
                c = No, they aren't.
                w = Yes,
                w = they are.
            }
            }
            }
            daimon
            {
            id = daimon2
            title = ""Daimon Title 2""

            chumon
            {
            id = chumon3
            title = ""Chumon Title 3""

            shomon
            {
                id = shomon3
                q = Are these cameras?
                c = No, they aren't.
                w = Yes,
                w = they are.
            }
            }
            }
            }";

            using (var tempFile = new TempFile(text))
            {
                var accessor = new EmpDocumentAccessor1_1();
                var mondaiDocument = accessor.Load(tempFile.Name);
                var userInfo = new EPuzzleUserInfo();

                Assert.AreEqual("document1", mondaiDocument.Id);

                var daimon = mondaiDocument.Items[0];

                Assert.AreEqual(@"""Daimon Title 1""", daimon.Name);
                Assert.IsNotEmpty(daimon.Id);

                {
                    var chumon = (Chumon)daimon.Items[0];
                    Assert.AreEqual(@"""Chumon Title 1""", chumon.Name);
                    Assert.IsNotEmpty(chumon.Id);

                    Assert.AreEqual(1, chumon.Items.Count());
                    var shomon = (Shomon)chumon.Items[0];
                    Assert.AreEqual("shomon1", shomon.Id);
                    Assert.AreEqual("Are these cameras?", shomon.Mondaibun);
                    Assert.AreEqual("No, they aren't.", shomon.CorrectAnswers.First().Text);
                    CollectionAssert.AreEquivalent(new [] { "No", ",", "they", "aren't", ".", "Yes,", "they are." }, shomon.MondaiWords.Select(x => x.Text).ToArray());

                    Assert.AreEqual(TimeSpan.FromSeconds(6d), chumon.GetTimeLimit(userInfo));
                }
                {
                    var daimon2 = (Daimon)mondaiDocument.Items[1];
                    Assert.AreEqual("daimon2", daimon2.Id);

                    var chumon2 = (Chumon)daimon2.Items[0];
                    Assert.AreEqual("chumon3", chumon2.Id);

                    var shomon = (Shomon)chumon2.Items[0];
                    Assert.AreEqual("shomon3", shomon.Id);
                    Assert.AreEqual("Are these cameras?", shomon.Mondaibun);
                    Assert.AreEqual("No, they aren't.", shomon.CorrectAnswers.First().Text);
                    CollectionAssert.AreEquivalent(new [] { "No", ",", "they", "aren't", ".", "Yes,", "they are." }, shomon.MondaiWords.Select(x => x.Text).ToArray());
                }

            }
        }
コード例 #8
0
        public void 括弧でまとめて指定()
        {
            var text = @"
            version = 1.1
            document
            {
            id = document0
            title =

            daimon
            {
            id = daimon0
            title =

            chumon
            {
            id = chumon0
            title =
            shuffle = true
            helpId =
            helpId =

            shomon
            {
                id = shomon0
                qestion = aaa
                correctAnswer = (This is) (a ball).
            }
            }
            }
            }";

            using (var tempFile = new TempFile(text))
            {
                var accessor = new EmpDocumentAccessor1_1();
                var mondaiDocument = accessor.Load(tempFile.Name);

            //				var element = EmpDocument.Load(tempFile.Name);
            //				var shomonElement = element.Body.GetAllItems().First(x => "shomon" == x.Name);
            //				Assert.AreEqual("(This is) (a ball).", shomonElement.GetValue("sei"));
            //				var mondaiDocument = element.GetMondaiDocument();

                var shomon = mondaiDocument.GetAllItems().OfType<Shomon>().First(x => "shomon0" == x.Id);

                CollectionAssert.AreEqual
                (
                    new []
                    {
                        new MondaiWord("This is"),
                        new MondaiWord("a ball"),
                        new MondaiWord("."),
                    },
                    shomon.MondaiWords
                );
            }
        }
コード例 #9
0
        public void LoadingAndSavingTest()
        {
            var text = @"version = 1.1
            document
            {
            id = document0
            title =
            daimon
            {
            id = daimon0
            title =
            chumon
            {
            id = chumon0
            title =
            shuffle = true
            helpId =
            helpId =
            shomon
            {
                id = shomon0
                display = all
                q = bbb
                c = They need two kind of support: economic and technical.
                sound
                {
                    file = They need two kind of support.wav
                    when = start
                    repeat = true
                }
            }
            shomon
            {
                id = shomon1
                display = all
                q = bbb
                c = They need two kind of support: economic and technical.
                inputMethod = card
                sound
                {
                    file = They need two kind of support.wav
                    when = start
                    numberOfTimes = 2
                }
            }
            shomon
            {
                id = shomon2
                display = all
                inputMethod = typing
                q = bbb
                c = They need two kind of support: economic and technical.
                sound
                {
                    file = They need two kind of support.wav
                    when = userRequest
                    numberOfTimes = 2
                }
            }
            }
            }
            }
            ";

            using (var tempFile = new TempFile(text))
            {
                var accessor = new EmpDocumentAccessor1_1();
                var mondaiDocument = accessor.Load(tempFile.Name);

                var shomons = mondaiDocument.GetAllItems().OfType<Shomon>().ToArray();
                Assert.AreEqual(3, shomons.Length);

                int i = 0;
                {
                    var shomon = shomons[i++];
                    var sound = shomon.Sounds.First();
                    Assert.AreEqual("They need two kind of support.wav", sound.FileName);
                    Assert.AreEqual(SoundIsPlayedWhen.Start, sound.IsPlayedWhen);
                    Assert.True(sound.IsRepeated);
                    Assert.AreEqual(1, sound.NumberOfTimes);
                    Assert.AreEqual(ShomonInputMethod.Card, shomon.InputMethod);
                    Assert.AreEqual("bbb", shomon.Mondaibun);
                    CollectionAssert.AreEqual(new []
                    {
                        new MondaiWord("They"),
                        new MondaiWord("need"),
                        new MondaiWord("two"),
                        new MondaiWord("kind"),
                        new MondaiWord("of"),
                        new MondaiWord("support"),
                        new MondaiWord(":"),
                        new MondaiWord("economic"),
                        new MondaiWord("and"),
                        new MondaiWord("technical"),
                        new MondaiWord("."),
                    }, shomon.MondaiWords);
                }
                {
                    var shomon = shomons[i++];
                    var sound = shomon.Sounds.First();
                    Assert.AreEqual("They need two kind of support.wav", sound.FileName);
                    Assert.AreEqual(SoundIsPlayedWhen.Start, sound.IsPlayedWhen);
                    Assert.False(sound.IsRepeated);
                    Assert.AreEqual(2, sound.NumberOfTimes);
                    Assert.AreEqual(ShomonInputMethod.Card, shomon.InputMethod);
                }
                {
                    var shomon = shomons[i++];
                    var sound = shomon.Sounds.First();
                    Assert.AreEqual("They need two kind of support.wav", sound.FileName);
                    Assert.AreEqual(SoundIsPlayedWhen.UserRequest, sound.IsPlayedWhen);
                    Assert.False(sound.IsRepeated);
                    Assert.AreEqual(2, sound.NumberOfTimes);
                    Assert.AreEqual(ShomonInputMethod.Typing, shomon.InputMethod);

                    // カード部分を取り除くかどうか保留
                    Assert.AreEqual(11, shomon.MondaiWords.Count());
                }

            /*
                using (var actual = new TempFile())
                {
                    accessor.Save(actual.Name, mondaiDocument);
                    TestUtility.CompareWithWinMerge(tempFile.Name, actual.Name);
                    FileAssert.AreEqual(tempFile.Name, actual.Name);
                }*/
            }
        }
コード例 #10
0
        public void LettersThatAreDisplayedOnCardに対応させる()
        {
            var text = @"
            version = 1.1
            document
            {
            id = document0
            title =

            daimon
            {
            id = daimon0
            title =

            chumon
            {
            id = chumon0
            title =
            shuffle = true
            helpId =
            helpId =

            shomon
            {
                id = shomon0
                display = all
                q = bbb
                c = They need two kind of support: economic and technical.
            }
            }
            }
            }";

            using (var tempFile = new TempFile(text))
            {
                var accessor = new EmpDocumentAccessor1_1();
                var mondaiDocument = accessor.Load(tempFile.Name);

            //				var element = EmpDocument.Load(tempFile.Name);
            //				var mondaiDocument = element.GetMondaiDocument();

                var shomon = (Shomon)mondaiDocument.GetItem("shomon0");
                Assert.AreEqual("bbb", shomon.Mondaibun);
                Assert.AreEqual(LettersThatAreDisplayedOnCard.All, shomon.LettersThatAreDisplayedOnCard);
            }
        }
コード例 #11
0
        public void helpIdに空文字を指定されたら無視する()
        {
            var text = @"
            version = 1.1
            document
            {
            id = document0
            title =

            daimon
            {
            id = daimon0
            title =

            chumon
            {
            id = chumon0
            title =
            shuffle = true
            helpId =
            helpId =

            ankimon
            {
                id = ankimon0
                item
                {
                    name =
                    split = a b
                }
                item
                {
                    name =
                    split = c+d e
                }
            }
            }
            }
            }";

            using (var tempFile = new TempFile(text))
            {
                var accessor = new EmpDocumentAccessor1_1();
                var mondaiDocument = accessor.Load(tempFile.Name);
                var chumon = mondaiDocument.GetItem("chumon0");
                Assert.IsEmpty(chumon.HelpIds);
            }
        }
コード例 #12
0
        public void 選択用カード生成テスト()
        {
            var text = @"
            version = 1.1
            document
            {
            id = document1
            title = documentC

            daimon
            {
            id = id1
            title = ""daimonTitle""

            chumon
            {
            id = chumon2-2
            title = ""chumonTitle""

            shomon
            {
                id = shomon1
                q = Are these cameras?
                correct = No, they aren't.
                c = Yes, they are.
            }
            }
            }
            }

            ";
            using (var tempFile = new TempFile(text))
            {
                var accessor = new EmpDocumentAccessor1_1();
                var mondaiDocument = accessor.Load(tempFile.Name);
                var userInfo = new EPuzzleUserInfo();

                Assert.AreEqual("document1", mondaiDocument.Id);

                var daimon = mondaiDocument.Items[0];

                Assert.AreEqual(@"""daimonTitle""", daimon.Name);
                Assert.IsNotEmpty(daimon.Id);

                var chumon = (Chumon)daimon.Items[0];
                Assert.AreEqual(@"""chumonTitle""", chumon.Name);
                Assert.IsNotEmpty(chumon.Id);

                var shomon = (Shomon)chumon.Items[0];
                Assert.AreEqual("shomon1", shomon.Id);
                Assert.AreEqual("Are these cameras?", shomon.Mondaibun);
                Assert.AreEqual("No, they aren't.", shomon.CorrectAnswers[0].Text);
                Assert.AreEqual("Yes, they are.", shomon.CorrectAnswers[1].Text);

                CollectionAssert.AreEquivalent(new [] { "No", ",", "they", "aren't", "Yes", "are", "." }, shomon.MondaiWords.Select(x => x.Text).ToArray());
                Assert.AreEqual(TimeSpan.FromSeconds(6d), chumon.GetTimeLimit(userInfo));
            }
        }
コード例 #13
0
        public void 括弧関連の不具合()
        {
            var text = @"
            version = 1.1
            document
            {
            id = document0
            title =

            daimon
            {
            id = daimon0
            title =

            chumon
            {
            id = chumon0
            title =
            shuffle = true
            helpId =
            helpId =

            shomon
            {
                id = shomon0
                q = bbb
                c = This watch cost me (7,500 yen).
            }
            }
            }
            }";

            using (var tempFile = new TempFile(text))
            {
                var accessor = new EmpDocumentAccessor1_1();
                var mondaiDocument = accessor.Load(tempFile.Name);

            //				var element = EmpDocument.Load(tempFile.Name);
            //				var mondaiDocument = element.GetMondaiDocument();

                var shomon = (Shomon)mondaiDocument.GetItem("shomon0");
                Assert.AreEqual("bbb", shomon.Mondaibun);
                CollectionAssert.AreEqual(new []
                {
                    new MondaiWord("This"),
                    new MondaiWord("watch"),
                    new MondaiWord("cost"),
                    new MondaiWord("me"),
                    new MondaiWord("7,500 yen"),
                    new MondaiWord("."),
                }, shomon.MondaiWords);
            }
        }
コード例 #14
0
        public void 括弧とクォーテーションに対応させる()
        {
            var text = @"
            version = 1.1
            document
            {
            id = document0
            title =

            daimon
            {
            id = daimon0
            title =

            chumon
            {
            id = chumon0
            title =
            shuffle = true
            helpId =
            helpId =

            shomon
            {
                id = shomon0
                q = bbb
                c = Not saying (""thank you"") is rude.
            }
            }
            }
            }";

            using (var tempFile = new TempFile(text))
            {
                var accessor = new EmpDocumentAccessor1_1();
                var mondaiDocument = accessor.Load(tempFile.Name);

            //				var element = EmpDocument.Load(tempFile.Name);
            //				var mondaiDocument = element.GetMondaiDocument();

                var shomon = (Shomon)mondaiDocument.GetItem("shomon0");
                Assert.AreEqual("bbb", shomon.Mondaibun);
                CollectionAssert.AreEqual(new []
                {
                    new MondaiWord("Not"),
                    new MondaiWord("saying"),
                    new MondaiWord(@"""thank you"""),
                    new MondaiWord("is"),
                    new MondaiWord("rude"),
                    new MondaiWord("."),
                }, shomon.MondaiWords);
            }
        }
コード例 #15
0
        public void セミコロンを分割するテスト()
        {
            var text = @"
            version = 1.1
            document
            {
            id = document0
            title =

            daimon
            {
            id = daimon0
            title =

            chumon
            {
            id = chumon0
            title =
            shuffle = true
            helpId =
            helpId =

            shomon
            {
                id = shomon0
                q = bbb
                c = We stopped talking; otherwise
            }
            }
            }
            }";

            using (var tempFile = new TempFile(text))
            {
                var accessor = new EmpDocumentAccessor1_1();
                var mondaiDocument = accessor.Load(tempFile.Name);

            //				var element = EmpDocument.Load(tempFile.Name);
            //				var mondaiDocument = element.GetMondaiDocument();

                var shomon = (Shomon)mondaiDocument.GetItem("shomon0");
                Assert.AreEqual("bbb", shomon.Mondaibun);
                CollectionAssert.AreEqual(new []
                {
                    new MondaiWord("We"),
                    new MondaiWord("stopped"),
                    new MondaiWord("talking"),
                    new MondaiWord(";"),
                    new MondaiWord("otherwise"),
                }, shomon.MondaiWords);
            }
        }
コード例 #16
0
        public void ダブルクォーテーションの不具合()
        {
            var text = @"
            version = 1.1
            document
            {
            id = document0
            title =

            daimon
            {
            id = daimon0
            title =

            chumon
            {
            id = chumon0
            title =
            shuffle = true
            helpId =
            helpId =

            shomon
            {
                id = shomon0
                q = bbb
                c = He said, ""If only she were here.""
            }
            }
            }
            }";

            using (var tempFile = new TempFile(text))
            {
                var accessor = new EmpDocumentAccessor1_1();
                var mondaiDocument = accessor.Load(tempFile.Name);

            //				var element = EmpDocument.Load(tempFile.Name);
            //				var mondaiDocument = element.GetMondaiDocument();

                var shomon = (Shomon)mondaiDocument.GetItem("shomon0");
                Assert.AreEqual("bbb", shomon.Mondaibun);

            /*			foreach (var item in shomon.MondaiWords)
                {
                    Console.WriteLine(item.Text);
                }*/

                Assert.AreEqual(@"He said, ""If only she were here.""", EmpDocument.先頭と末尾のダブルクォーテーションを取り除く(@"He said, ""If only she were here."""));

            //				var t = element.Body.GetAllItems().Where(x => "sei" == x.Name).First().Value;
            //				Assert.AreEqual(@"He said, ""If only she were here.""", t);
                CollectionAssert.AreEqual(new []
                {
                    new MondaiWord("He"),
                    new MondaiWord("said"),
                    new MondaiWord(","),
                    new MondaiWord(@""""),
                    new MondaiWord("If"),
                    new MondaiWord("only"),
                    new MondaiWord("she"),
                    new MondaiWord("were"),
                    new MondaiWord("here"),
                    new MondaiWord("."),
                    new MondaiWord(@""""),
                }, shomon.MondaiWords);
            }
        }
コード例 #17
0
        public void ヴァージョン違い例外()
        {
            var text =
            @"
            version = 1.0

            document
            {}
            ";
            // 正しくは1.1
            var accessor = new EmpDocumentAccessor1_1();
            Assert.Throws<EmpException>(() =>
            {
                using (var tempFile = new TempFile(text))
                {
                    accessor.Load(tempFile.Name);
                }
            });
        }