Differences between revisions 8 and 9
Revision 8 as of 2007-08-11 12:20:48
Size: 4958
Editor: XiaoQi
Comment:
Revision 9 as of 2009-12-25 07:09:17
Size: 4959
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
 1. `本章标题`:''Test-First Programming'' '''以测试优先为原则的'''编程 (./) '''测试优先'''编程[[BR]]
 (!) KISS 是改译的主要理由。[:../2006-03-22] 中提出的“测试导向编程”也是个不错的名字,但我 Google 了一下,933:1,“测试优先编程”获胜。况且这样的译法并不少见(eg. ''broad-first search'',广度优先搜索)。
 1. `本章标题`:''Test-First Programming'' '''以测试优先为原则的'''编程 (./) '''测试优先'''编程<<BR>>
 (!) KISS 是改译的主要理由。[[../2006-03-22]] 中提出的“测试导向编程”也是个不错的名字,但我 Google 了一下,933:1,“测试优先编程”获胜。况且这样的译法并不少见(eg. ''broad-first search'',广度优先搜索)。
Line 10: Line 10:
 1. `例14.2上`:'''''Run romantest1.py with the -v command-line option''', which will give more verbose output...''[[BR]]
 '''运行 romantest1.py 带有 -v 选项的命令行'''可以得到更详细的输出信息,……[[BR]]
 (!) -_-明显不通。后面作了类似的改动。[[BR]]
 1. `例14.2上`:'''''Run romantest1.py with the -v command-line option''', which will give more verbose output...''<<BR>>
 '''运行 romantest1.py 带有 -v 选项的命令行'''可以得到更详细的输出信息,……<<BR>>
 (!) -_-明显不通。后面作了类似的改动。<<BR>>
Line 15: Line 15:
 1. `例14.2, (4)`:'''一个'''测试用例没能通过时,unittest 会区分是失败(failures)还是错误(errors)。[[BR]]  1. `例14.2, (4)`:'''一个'''测试用例没能通过时,unittest 会区分是失败(failures)还是错误(errors)。<<BR>>
Line 19: Line 19:
 1. `例14.5, (1)`'''''toroman does, in fact, always return uppercase''', because romanNumeralMap defines the Roman numeral representations as uppercase. So this test passes already.''[[BR]]
 '''toroman 通过,事实上其返回值总是大写的''',因为 romanNumeralMap 定义的罗马字符都是以大写字母表示的。因此这个测试已经通过了。[[BR]]
 1. `例14.5, (1)`'''''toroman does, in fact, always return uppercase''', because romanNumeralMap defines the Roman numeral representations as uppercase. So this test passes already.''<<BR>>
 '''toroman 通过,事实上其返回值总是大写的''',因为 romanNumeralMap 定义的罗马字符都是以大写字母表示的。因此这个测试已经通过了。<<BR>>
Line 23: Line 23:
 1. `例14.5, (3)`:''However, the function does not "work" for bad values;...''[[BR]]
 但是,函数还没办法'''“'''处理'''”'''无效输入,……[[BR]]
 1. `例14.5, (3)`:''However, the function does not "work" for bad values;...''<<BR>>
 但是,函数还没办法'''“'''处理'''”'''无效输入,……<<BR>>
Line 30: Line 30:
 1. `Para -1`:''When all the unit tests for an '''entire''' module pass, stop coding the module.''[[BR]]
 一旦'''一个完整'''模块的单元测试通过了,停止编写这个模块。[[BR]]
 1. `Para -1`:''When all the unit tests for an '''entire''' module pass, stop coding the module.''<<BR>>
 一旦'''一个完整'''模块的单元测试通过了,停止编写这个模块。<<BR>>
Line 36: Line 36:
 1. `例14.11, (2)`:尚不能完全相信,理论上存在这种可能性:toroman 存在错误而导致一些特定输入产生错误罗马数字表示 '''和''' fromroman 存在相应的错误,把 toroman 错误产生的这些罗马数字错误地转换为最初的整数。[[BR]]  1. `例14.11, (2)`:尚不能完全相信,理论上存在这种可能性:toroman 存在错误而导致一些特定输入产生错误罗马数字表示 '''和''' fromroman 存在相应的错误,把 toroman 错误产生的这些罗马数字错误地转换为最初的整数。<<BR>>
Line 41: Line 41:
 1. `4.`:'''有五个字符'''不能被重复:[[BR]]
 (./) '''含五的字符'''不能被重复:[[BR]]
 1. `4.`:'''有五个字符'''不能被重复:<<BR>>
 (./) '''含五的字符'''不能被重复:<<BR>>
Line 45: Line 45:
 1. `例14.13, (2)`:''More importantly, the bad input tests pass. For instance, '''the malformed antecedents test checks cases like MCMC.'''''[[BR]]
 更重要的是,无效输入测试也通过了。例如,'''前面那个测试用例需要检查 MCMC 之类的情形。'''[[BR]]
 1. `例14.13, (2)`:''More importantly, the bad input tests pass. For instance, '''the malformed antecedents test checks cases like MCMC.'''''<<BR>>
 更重要的是,无效输入测试也通过了。例如,'''前面那个测试用例需要检查 MCMC 之类的情形。'''<<BR>>

8-6<X14>roman.xml 测试优先编程

  1. 本章标题Test-First Programming 以测试优先为原则的编程 (./) 测试优先编程
    (!) KISS 是改译的主要理由。../2006-03-22 中提出的“测试导向编程”也是个不错的名字,但我 Google 了一下,933:1,“测试优先编程”获胜。况且这样的译法并不少见(eg. broad-first search,广度优先搜索)。

  2. 频繁typo:他们 (./) 它们 (!) 怀疑是翻译时用了盲目的替换

14.1 roman.py, 第 1 阶段

  1. Para 1:到目前为止,单元测试已经完成,是时候开始编写被单元测试测试的代码的时候 {X} 了。但在逐步完成 roman.py 的同时你会看到它们一个个地通过测试 {X}

  2. 例14.1, (1):这 {i} 是如何定义你自己的 Python 异常。异常 {i} (Exception)也是类,通过继承已有的异常,你可以创建自定义的异常。

  3. 例14.2上Run romantest1.py with the -v command-line option, which will give more verbose output...
    运行 romantest1.py 带有 -v 选项的命令行可以得到更详细的输出信息,……
    (!) -_-明显不通。后面作了类似的改动。
    (./) 用命令行选项 -v 运行 romantest1.py 可以得到更详细的输出信息

  4. 例14.2Output of romantest1.py against roman1.py (./) 以 romantest1.py 测试 roman1.py 的输出

  5. 例14.2, (4)一个测试用例没能通过时,unittest 会区分是失败(failures)还是错误(errors)。
    (./) 当某个测试用例没能通过时,unittest 会区分是失败(failures)还是错误(errors)。

14.2 roman.py, 第 2 阶段

  1. 例14.5, (1)toroman does, in fact, always return uppercase, because romanNumeralMap defines the Roman numeral representations as uppercase. So this test passes already.
    toroman 通过,事实上其返回值总是大写的,因为 romanNumeralMap 定义的罗马字符都是以大写字母表示的。因此这个测试已经通过了。
    (./) 事实上,toroman 的返回值总是大写的,因为 romanNumeralMap 定义的罗马字符都是以大写字母表示的。因此这个测试已经通过了。

  2. 例14.5, (2):……以及可能的最长的罗马数字表示(3888 对应的(./) 对应于 3888

  3. 例14.5, (3)However, the function does not "work" for bad values;...
    但是,函数还没办法处理无效输入,……
    (!) 翻译成中文后,引号变得多余了。

14.3 roman.py, 第 3 阶段

  1. 例14.6, (2):……第二个参数是可选的,如果给定,则 {i} 在异常未被处理时显示于追踪信息(trackback)之中。

  2. 例14.8, (2):……当一个非整数传递给 toroman {i} ,int(n) <> n 检查出问题并引发 NotIntegerError 异常,……

  3. Para -1When all the unit tests for an entire module pass, stop coding the module.
    一旦一个完整模块的单元测试通过了,停止编写这个模块。
    (./) 一旦整个模块的单元测试通过了,停止编写这个模块。

14.4 roman.py, 第 4 阶段

  1. 例14.9, (1):这和 toroman 的工作模式很相像(./) 相似

  2. 例14.11, (2):尚不能完全相信,理论上存在这种可能性:toroman 存在错误而导致一些特定输入产生错误罗马数字表示 fromroman 存在相应的错误,把 toroman 错误产生的这些罗马数字错误地转换为最初的整数。
    (./) 尚不能完全相信,理论上存在这种可能性:toroman 存在错误而导致一些特定输入会产生错误的罗马数字表示,并且 fromroman 存在相应的错误,把 toroman 错误产生的这些罗马数字错误地转换为最初的整数。

14.5 roman.py, 第 5 阶段

  1. 罗马数字规则, 2.:44 表示为 XLIV (比50小10, <!> 比 5 小 1) (./) 加上

  2. 4.有五个字符不能被重复:
    (./) 含五的字符不能被重复:
    (!) 还请参看 re 一章。

  3. 5.:罗马数字经常 <!> 从高位到低位书写 (./) 一般

  4. 例14.13, (2)More importantly, the bad input tests pass. For instance, the malformed antecedents test checks cases like MCMC.
    更重要的是,无效输入测试也通过了。例如,前面那个测试用例需要检查 MCMC 之类的情形。
    (./) 更重要的是,无效输入测试也通过了。例如,上面这个用例测试了 MCMC 之类的情形。

  5. 例14.13, (3):正则表达式捕捉了所有 {X} 你在编写测试用例时所能预见的所有情况。

DiveIntoPythonZh/2007-08-06 (last edited 2009-12-25 07:09:17 by localhost)