什么是这个测试输出意味着python

时间:2018-03-13 20:39:12

标签: python github open-source

我正在开发一个开源项目。该项目的目标是创建一个俄罗斯方块游戏。在构建游戏时需要进行一系列测试。第一个测试确保计算机可以找到您的代码。基本上只是将文件保存在正确的位置。我每次都通过它。然后第二个测试是打印游戏板。这是传递第二个测试的p命令代码:

   def test2():
        while True:
         qp = raw_input('')
         if qp=='p':

          for i in range(0,22):
             for j in range(0,10):
               print'.',
             print''
        else:
           return exit()

    test2()

它打印输出,一个点矩阵。 10 x 22输出的点,类似于俄罗斯方块布局。然后代码转到步骤3,即使用'g命令'将一些内部表示填充到矩阵中。它还说“输入格式应该与'p'命令产生的输出相同”。当它表示输入格式是否意味着代码?我尝试了各种代码,最终将我的两个参数合并到一个while语句中。特别是这句话:

  def test3():
        while True:
            qp = raw_input('')
            if qp == 'p' or qp == 'g':

                for i in range(0, 22):
                    for j in range(0, 10):
                        print'.',
                    print''

            else:
                return exit()

    test3()

显然,当我在PyCharm调试器中运行代码时,无论我输入'p'还是'g',它都会抛出一个空白的10x22矩阵。我猜这是预期的,因为他们使用相同的while循环。但是当我在我的mac终端中运行它时,它不会产生空白矩阵。它会产生预期输出的可怕间隔和失真输出(https://imgur.com/a/ryNsN)(可以在底部的链接上看到)。所以我知道我的代码是错误的,但我认为这是因为我在等待测试结果时误解了提示3.程序的含义是什么:

 The 'g' command instructs learntris to read 22 lines
of text from the standard input stream, and use the
characters on these lines to populate some internal
representation of the matrix.

The letter 'g' is a mnemonic for the word 'given', as
in: "given the following matrix...."

The input format should be identical to the output
produced by the 'p' command.

The letters used in the representation correspond to
the set of colors used for blocks in the game:

. = empty (black)     b = blue         c = cyan
g = green             m = magenta      o = orange
r = red               y = yellow

您可以在此处详细了解测试3的预期输出:https://github.com/LearnProgramming/learntris/blob/master/testplan.org#establish-a-way-to-set-the-entire-matrix-g

所以任何人都可以帮我弄清楚“输入格式应该与'p'命令产生的输出相同”意味着我可以解决这个代码并进入下一步吗?

1 个答案:

答案 0 :(得分:1)

很简单,p命令的输出成为g命令的输入;这是一个简单的数据流。不要将两个命令的代码组合在一起。首先编码p命令,然后通过眼睛检查输出。然后,对g命令进行编码 - 第一步是使其读取p命令生成的文件。