Đang chuẩn bị liên kết để tải về tài liệu:
Dive Into Python-Chapter 13. Unit Testing
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tham khảo tài liệu 'dive into python-chapter 13. unit testing', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Chapter 13. Unit Testing 13.1. Introduction to Roman numerals In previous chapters you dived in by immediately looking at code and trying to understand it as quickly as possible. 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. 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. You saw the mechanics of constructing and validating Roman numerals in Section 7.3 Case Study Roman Numerals but now let s step back and consider what it would take to expand that into a two-way utility. The rules for Roman numerals lead to a number of interesting observations 1. There is only one correct way to represent a particular number as Roman numerals. 2. The converse is also true if a string of characters is a valid Roman numeral it represents only one number i.e. it can only be read one way . 3. There is a limited range of numbers that can be expressed as Roman numerals specifically 1 through 3999. The Romans did have several ways of expressing larger numbers for instance by having a bar over a numeral to represent that its normal value should be multiplied by 1000 but you re not going to deal with that. For the purposes of this chapter let s stipulate that Roman numerals go from 1 to 3999. 4. There is no way to represent 0 in Roman numerals. Amazingly the ancient Romans had no concept of 0 as a number. Numbers were for counting things you had how can you count what you don t have 5. There is no way to represent negative numbers in Roman numerals. 6. There is no way to represent fractions or non-integer numbers in Roman numerals. Given all of this what would you expect out of a set of functions to convert to and from Roman numerals roman.py requirements 1. toRoman should return the Roman numeral representation for all integers 1 to 3999. 2. toRoman should fail when given an integer outside the range 1 to 3999. 3. .