进行多项选择测试


14

我给你测试!您的测试就是测试。测试是用测试人员提供给您的测试来测试被测者,其中包含少量测试代码。具体来说,您将提供选择输入的多选测试。

在此挑战中,您必须输入如下内容:

1. Our site is called Programming Puzzles & Code ________.
A: Debugging
*B: Golf
C: Hockey
D: Programming
2. What is the *most* popular tag on our site?
A: [debug]
B: [program]
*C: [code-golf]
D: [number]
E: [c++]
3. We are part of the ________ Exchange network.
*A: Stack
B: Code
C: Programmer
D: Hockey
4. Is this the first question?
A: Yes
*B: No
5. Is this the last question?
*A: Yes
B: No

这是正在进行测试的示例:

1. Our site is called Programming Puzzles & Code ________.
A: Debugging
B: Golf
C: Hockey
D: Programming
answer: B
correct!

2. What is the *most* popular tag on our site?
A: [debug]
B: [program]
C: [code-golf]
D: [number]
E: [c++]
answer: C
correct!

3. We are part of the ________ Exchange network.
A: Stack
B: Code
C: Programmer
D: Hockey
answer: B
incorrect! the answer was A

4. Is this the first question?
A: Yes
B: No
answer: B
correct!

5. Is this the last question?
A: Yes
B: No
answer: B
incorrect! the answer was A

overview:
3 correct, 2 incorrect (60%)

3. We are part of the ________ Exchange network.
you chose B: Code
the answer was A: Stack

5. Is this the last question?
you chose B: No
the answer was A: Yes

正式规格:

  • 输入值
    • 如果一行以数字开头,后接点和空格,则表示该数字是一个问题。数字始终从1开始,每个问题最多上升1。
    • 如果一行以可选的星号,字母,冒号和空格开头,则为答案。答案也将始终是顺序的。每个问题只有一个正确答案。
    • 除了前面提到的方式,一行不会以任何其他方式开始。
    • 可以以任何方式(从文件,stdin等读取)接受输入,但不得将其硬编码到程序中。
  • 输出(考试阶段)
    • 首先,顺序打印每个问题。根据输入内容打印问题及其答案,但不要打印表示正确答案的星号。
    • 然后,打印换行符和"answer: "。等待用户输入。用户输入将始终对应于答案。
    • 如果正确答案(带星号的答案)与用户输入的答案相同,请输出"correct!"。否则,输出"incorrect! the answer was " + correct_letter
    • 用空白行分隔每个问题,然后重复前面的输出步骤,直到没有其他问题为止。
  • 输出(概述阶段)
    • 打印"overview: ",然后换行。
    • 打印"{number of correct answers} correct, {incorrect answers} incorrect ({percent correct, rounded to the nearest whole number}%)"(当然,用大括号将短语替换为相应的值)。然后打印空白行以保持间距。
    • 现在,对于每个错误的问题,先打印问题(而不是答案),然后在新行上"you chose " + answer_you_chose,然后在另一行上"the answer was " + correct_answer。用空白行分隔每个错误答案的概述。
  • 为了通过按字面解释来减少作弊,当在此处给出相同的输出,并且在考试阶段提供相同的输入时,程序必须输出与示例输出完全相同的东西。

这是;最短的代码胜出!(并获得一个A +(绿色复选标记)!)


2
很好的挑战,但我希望样本测试能够包含棘手的情况,例如\d\. \w: 并且\*在问题/答案中间。(例如,当前*可以用消除y/*//,而正确的方法冗长如s/^\*//。)
manatwork 2013年

2
我们需要允许行继续吗?我的意思是,会有几行不是以“ 1。”或“ A:”?如果是,请在样本测试中包括此类情况。
manatwork 2013年

@manatwork(第一条评论)好的,编辑(第二条评论)不,您不要。我会澄清。
门把手

1
那么您将如何测试该测试?
Joe Z.

2
@JoeZ。嗯...不确定您的意思...我确实为测试人员提供了测试用例以测试您的测试人员
Doorknob

Answers:


2

Perl 5,279

$y=correct;@w=(the,$n=answer,was);map{s/^\*((.+?):.+)/$a=$1/me;print"$_$n: ";chop($@=<>);print$@eq($l=$2)?++$d&&"$y!

":(/^\d.+/,$o.=$&,/^$@.+/m,$o.="
you chose: $&
@w $a

")&&"in$y! @w $l

"}@_=split/(?=^\d)/m,join"",<>;printf"overview:
$d $y, %d in$y (%d%)

$o",@_-$d,$d/@_*100

注意:换行符是输出格式所必需的。

每当我觉得自己不能再打高尔夫球了,我就会学到一些新东西!它的标点符号正逐渐变得比清晰的文字更...我认为这是一件好事吗?

用法:perl -e '...' test.txtperl test.pl test.txt

如果选择列表中未显示的选项,则概述中将显示不正确的输出(you chose: 1. Our site is called Programming Puzzles & Code ________.例如,将显示)。

运行示例


请显示输入和输出的示例。
DavidC

@DavidCarraher通过showterm.io将更新的链接添加到输出。认为它会比静态输出略胜一筹,尽管它仍然无法捕获与终端中完全相同的输出。
Dom Hastings 2013年

这样可以很好地了解程序的工作方式。
DavidC

3

Mathematica 144

这可能是无效的尝试。我将问题与输入中的每个答案分开。我还用一个单独的字段中的字母表示正确答案,而不是在替代方法之前使用星号。

无论如何...

数据

questions={{{"\n1. Our site is called Programming Puzzles & Code ________.\n","A: Bugging\n","B: Golf\n","C: Hockey\n","D: Programming\n"},"B"},{{"\n2. What is the most popular tag on our site? \n","A: [debug]\n","B: [program]\n","C: [code golf]\n","D: [number]\n"},"C"},{{"\n3. We are part of the _______ Exchange network. \n","A: Stack\n","B: Code\n","C: Programmer\n","D: Hockey\n"},"A"},{{"\n4. Is this the first question? \n","A: Yes\n","B: No\n"},"B"},{{"\n5. Is this the last question? \n","A: Yes\n","B: No\n"},"A"}};

通过对话框输入每个问题的答案。问题,答案和反馈已打印出来。

f@x_:=
Print[If[((r=ChoiceDialog[Print[""<>#,"\nanswer: "];""<>#,StringTake[Rest@#,1]])==#2),
r<>"\ncorrect!", r<>"\nincorrect, the answer is "<>#2]&@@x] 

测试

f /@ questions

对话框选择


哇,令人印象深刻!输入的格式仍然不正确。。。仍然如此,这对于代码的简洁性以及它的功能非常重要!
Doorknob

谢谢。将输入字符串按摩成对Mathematica友好的结构当然是可能的,但是它将隐藏当前不合格的解决方案的基础。
DavidC 2013年

真好 短四个字符:g@{a_,b_}:=Print[If[(r=ChoiceDialog[Print[""<>a,"\nanswer: "];""<>a,Rest@a~StringTake~1])==b,r<>"\ncorrect!",r<>"\nincorrect, the answer is "<>b]]
威兹德先生

并使用Print@If[...]而不是保存一个Print[If[...]]
威兹德先生2013年

2

爪哇-1210

int i,o;String q;String[]s={"1. Our site is called Programming Puzzles & Code ________.\n","2. What is the most popular tag on our site?\n","3. We are part of the ________ Exchange network.\n","4. Is this the first question?\n","5. Is this the last question?\n"},b={"B","C","A","B","A"},p=new String[5];String[][]a={{"A: Debugging\n","B: Golf\n","C: Hockey\n","D: Programming\n","answer: "},{"A: [debug]\n","B: [program]\n","C: [code-golf]\n","D: [number]\n","E: [c++]\n","answer: "},{"A: Stack\n","B: Code\n","C: Programmer\n","D: Hockey\n","answer: "},{"A: Yes\n","B: No\n","answer: "},{"A: Yes\n","B: No\n","answer: "}};java.util.Map<String,Integer>m=new java.util.HashMap(){{put("A",0);put("B",1);put("C",2);put("D",3);put("E",4);}};java.util.Scanner u=new java.util.Scanner(System.in);for(i=0;i<5;i++){q=s[i];for(o=0;o<a[i].length;)q+=a[i][o++];System.out.print(q);if(b[i].equals(p[i]=u.nextLine()))q="correct!";else q="incorrect! the answer was "+b[i];System.out.println(q+"\n");}q="";o=0;for(i=0;i<5;i++)if(b[i].equals(p[i]))o++;else q+=s[i]+"you chose "+a[i][m.get(p[i])]+"the answer was "+a[i][m.get(b[i])]+"\n";System.out.println("overview:\n"+o+" correct, "+(5-o)+" incorrect ("+o*100/5+"%)\n\n"+q);

格式化:1980

String[] s = {"1. Our site is called Programming Puzzles & Code ________.\n",
        "2. What is the most popular tag on our site?\n",
        "3. We are part of the ________ Exchange network.\n",
        "4. Is this the first question?\n",
        "5. Is this the last question?\n"};
    String[][] a = {
        {"A: Debugging\n", "B: Golf\n", "C: Hockey\n", "D: Programming\n", "answer: "},
        {"A: [debug]\n", "B: [program]\n", "C: [code-golf]\n", "D: [number]\n", "E: [c++]\n", "answer: "},
        {"A: Stack\n", "B: Code\n", "C: Programmer\n", "D: Hockey\n", "answer: "},
        {"A: Yes\n", "B: No\n", "answer: "},
        {"A: Yes\n", "B: No\n", "answer: "}};

    java.util.Map<String, Integer> m = new java.util.HashMap<String, Integer>() {
        {
            put("A", 0);
            put("B", 1);
            put("C", 2);
            put("D", 3);
            put("E", 4);
        }
    };
    String[] b = {"B", "C", "A", "B", "A"};
    String[] p = new String[5];
    java.util.Scanner u = new java.util.Scanner(System.in);
    String q;
    int i;
    int o;
    for (i = 0; i < 5; i++) {
        q = s[i];
        for (o = 0; o < a[i].length;) {
            q += a[i][o++];
        }
        System.out.print(q);
        if (b[i].equals(p[i] = u.nextLine())) {
            q = "correct!";
        } else {
            q = "incorrect! the answer was " + b[i];
        }
        System.out.println(q + "\n");
    }
    q = "";
    o = 0;
    for (i = 0; i < 5; i++) {
        if (b[i].equals(p[i])) {
            o++;
        } else {
            q += s[i] + "you chose " + a[i][m.get(p[i])] + "the answer was " + a[i][m.get(b[i])] + "\n";
        }
    }
    System.out.println("overview:\n" + " correct, " + (5 - o) + " incorrect (" + o * 100 / 5 + "%)\n\n" + q);

这当然不会是最短的,但它们都是独立的


0

哈斯克尔,598

import System.Environment
import System.IO
n=putStrLn
p=putStr
d#s=p$show d++s
v&(m:a)=n m>>q[]""a>>= \(r,(s,t))->n s>>n"">>b v m t&r
(r,w,s)&[]=n"overview:">>r#" correct, ">>w#" incorrect (">>((100*r)`div`(r+w))#"%)\n">>mapM_ n s
b(r,w,s)m t|null t=(r+1,w,s)|1<3=(r,w+1,s++"":m:t)
q u c(('*':a):r)=q u a(a:r)
q u c(a@(o:':':_):r)=n a>>q(([o],a):u)c r
q u c r=p"answer: ">>hFlush stdout>>(\i->(r,a(maybe i id$lookup i u)c))`fmap`getLine
a j c|j==c=("correct!",[])|1<3=("incorrect! the answer was "++[head c],["you choose "++j,"the answer was "++c])
main=getArgs>>=readFile.head>>=((0,0,[])&).lines

比我想要的更长的时间。它已设置为Wiki,所以请尽情享受吧!

las,我们在刷新标准输出时丢失了32个字符。如果从名为“ t”的固定文件而不是在命令行中指定读取测试脚本,则可以另外保存38个字符。

在问题中给出的输入上运行时:

& runhaskell 15961-Tester.hs 15961-test.txt 
1. Our site is called Programming Puzzles & Code ________.
A: Debugging
B: Golf
C: Hockey
D: Programming
answer: B
correct!

2. What is the *most* popular tag on our site?
A: [debug]
B: [program]
C: [code-golf]
D: [number]
E: [c++]
answer: C
correct!

3. We are part of the ________ Exchange network.
A: Stack
B: Code
C: Programmer
D: Hockey
answer: B
incorrect! the answer was A

4. Is this the first question?
A: Yes
B: No
answer: B
correct!

5. Is this the last question?
A: Yes
B: No
answer: B
incorrect! the answer was A

overview:
3 correct, 2 incorrect (60%)

3. We are part of the ________ Exchange network.
you choose B: Code
the answer was A: Stack

5. Is this the last question?
you choose B: No
the answer was A: Yes
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.