2006-03-21 校对记要

校对文件: roman.xml

章节: [http://www.woodpecker.org.cn/obp/diveintopython-zh-5.4/zh-cn/dist/htmlflat/diveintopython.html#roman 第13章]

[http://www.woodpecker.org.cn/obp/diveintopython-zh-5.4/zh-cn/dist/htmlflat/diveintopython.html#roman.intro 13.1]

1st paragraph 2nd sentence:

Now that you have some Python under your belt, you're going to step back and look at the steps that happen before the code gets written.

现在你以对 Python 更多的了解将回顾这个程序并从其代码开发之前入手。

既然你已对Python 有了一定的了解,那么接下来将回顾这个程序并从其代码被开发之前入手。

2nd paragraph 1st sentence:

In the next few chapters, you're going to write, debug, and optimize a set of utility functions to convert to and from Roman numerals.

在接下来的几章中,你将会编写,纠错以及优化一系列使用函数来进行罗马数字和阿拉伯数字之间的转换。

在接下来的几章中,你将编写、调试和优化一系列工具函数来进行罗马数字和阿拉伯数字之间的转换。

roman.py 功能需求 中所有的valid翻译成“有效”invalid翻译成“无效”较翻译成“合法”“非法”合适。

需求第6点:

6. If you take a number, convert it to Roman numerals, then convert that back to a number, you should end up with the number you started with. So fromRoman(toRoman(n)) == n for all n in 1..3999.

将一个数转换为罗马数字表示,再转换回阿拉报数字表示后应该和最初的数相同。因此,fromRoman(toRoman(n)) == n 对于 1..3999 之间所有 n 都适用。

将一个数转换为罗马数字表示,再转换回阿拉伯数字表示后应该和最初的数相同。因此,fromRoman(toRoman(n)) == n 对于 1..3999 之间所有 n 都适用。

需求第7点:

7. toRoman should always return a Roman numeral using uppercase letters.

toRoman 返回的罗马数字应该适用大写字母。

toRoman 返回的罗马数字应该使用大写字母。

last sentence between parentheses

short answer: haphazardly and inconsistently

简言之:充满偶然性和异然性

简言之:充满偶然性和反复无常

[http://www.woodpecker.org.cn/obp/diveintopython-zh-5.4/zh-cn/dist/htmlflat/diveintopython.html#roman.divein 13.2]

1st paragraph:

Now that you've completely defined the behavior you expect from your conversion functions, you're going to do something a little unexpected: you're going to write a test suite that puts these functions through their paces and makes sure that they behave the way you want them to. You read that right: you're going to write code that tests code that you haven't written yet.

现在你已经定义了你的转换程序所应有的功能,下面一步有点令你出乎意料:你将要开发一个测试组建将使用你未来的函数以确保它们工作正常。没错:你将为还未开发的程序开发测试代码。

现在你已经定义了你的转换程序所应有的功能,下面一步会有点儿出乎你的意料:你将要开发一个测试组件(test suite)来测试你未来的函数以确保它们工作正常。没错:你将为还未开发的程序开发测试代码。

2nd paragraph:

This is called unit testing, since the set of two conversion functions can be written and tested as a unit, separate from any larger program they may become part of later. Python has a framework for unit testing, the appropriately-named unittest module.

这就是所谓的单元测试,由于这两个转换程序组成可以被当作一个单元共同开发和测试,而不去考虑他们可能今后成为一个大程序的一部分。 Python 有一个单元测试框架,被恰如其分地称作 unittest 模块。

这就是所谓的单元测试,因为这两个转换函数可以被当作一个单元来开发和测试,不用考虑它们可能今后成为一个大程序的一部分。 Python 有一个单元测试框架,被恰如其分地称作 unittest 模块。

hints: unittest is included with Python 2.1 and later. Python 2.0 users can download it from pyunit.sourceforge.net.

unittest 已被包含于 Python 2.1 和之后的版本中。 Python 2.0 用户则可以从 pyunit.sourceforge.net下载。

Python 2.1 和之后的版本已经包含了unittest。Python 2.0的用户则可以从 pyunit.sourceforge.net下载。

3rd paragraph:

1st sentence

Unit testing is an important part of an overall testing-centric development strategy.

单元测试是核心测试开发技巧的一部分。

单元测试是以测试为核心开发策略的重要组成部分。

last sentence

Unit testing is not a replacement for higher-level functional or system testing, but it is important in all phases of development:

单元测试不能取代更高层面的有效性和系统测试,但在开发的每个阶段都很重要。

单元测试不能取代更高层面的功能和系统测试,但在开发的每个阶段都很重要。

2nd item in the list

2nd sentence When all the test cases pass, the function is complete. 通过了测试程序就开发完成了。 通过了所有测试用例程序就完全(实现)了。

3rd item in the list

last sentence between parentheses

“But sir, all the unit tests passed when I checked it in...”

但是 先生, 我检查过,所有的单元测试都通过了......”

“但是,先生, 我检入(check in)代码时所有的单元测试都通过了......”

last item in the list

When writing code in a team, it increases confidence that the code you're about to commit isn't going to break other peoples' code, because you can run their unittests first. (I've seen this sort of thing in code sprints. A team breaks up the assignment, everybody takes the specs for their task, writes unit tests for it, then shares their unit tests with the rest of the team. That way, nobody goes off too far into developing code that won't play well with others.)

在团队开发时,因为你可以事先运行他人的单元测试代码,所以可以使你有信心自己的代码不至于另他人的代码崩溃。(我曾经见到过, 一个团队共同分担的工作中,每个人都根据自己部分的需求开发单元测试,然后大家共同应用这些单元测试。 这样一来,没有人会出太大的偏差而导致不融于团队。)

在团队开发时,可以使你有信心,保证自己提交的代码不会破坏其他人的代码,因为你可以先运行其他人的单元测试代码。(我在 “代码风暴”中见过这种事情。一个团队将任务拆分,每个人都根据自己那部分的需求开发单元测试,然后与其他成员共享。没有人会出太大的偏差而导致代码无法集成。)