2014-04-24 23:28

题目:玩象棋游戏,你要设计一个bool型的方法来检测一个棋子能否移动到指定位置。

解法:不同的棋子有不同的移动规则,那么应该采取棋子基类实现接口,各个棋子子类来实现的方式。棋子除了类型之外,还必须要记录当前位置,作为判断的依据。而要移到的位置,则作为参数传给方法。不过这个题目出现在软件测试的章节里,应该是要描述如何测试吧。没学过系统的测试方法,遇到这种题的话还真没办法。

代码:

 // 12.3 You're testing a method canMoveTo(int x, int y), which is a member method of a class Piece. Piece represents a piece in the chess game. How would you perform the testing?
// Answer:
// 1. Apparently every kind of pieces in chess has its own rule of moving. So the class Piece must be an abstract class, which will inherited by various kinds of specific pieces.
// 2. You always have to check if (x, y) is out of border. So this will be included in base class Piece.
// 3. Every piece has its own rule of moving, so the derived class will have to implement its own rule(), which will be executed by canMoveTo().
// 4. The class Piece should look like this:
// 5. The base class will have an interface named rule(), which will be implemented by derived class.
class Piece {
public:
virtual bool canMoveTo(int x, int y);
private:
// ...
virtual bool rule(int x, int y) = ;
};
// 6. Thus, the test should cover two parts:
// 6.a. The coordinates (x, y) will cover in-bound and out-of-bound cases.
// 6.b. Every rule() function will be executed inside canMoveTo(), thus the test will also be included here.

《Cracking the Coding Interview》——第12章:测试——题目3的更多相关文章

  1. Cracking the coding interview 第一章问题及解答

    Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...

  2. 《Cracking the Coding Interview》读书笔记

    <Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...

  3. Cracking the coding interview

    写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...

  4. Cracking the coding interview目录及资料收集

    前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...

  5. Cracking the Coding Interview(Trees and Graphs)

    Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...

  6. Cracking the Coding Interview(Stacks and Queues)

    Cracking the Coding Interview(Stacks and Queues) 1.Describe how you could use a single array to impl ...

  7. 《Cracking the Coding Interview》——第12章:测试——题目6

    2014-04-25 00:53 题目:你要如何测试一个分布式银行系统的ATM机? 解法:ATM是Automatic Teller Machine,取钱的.我想了半天,没找到什么很清晰的思路,也许是因 ...

  8. 《Cracking the Coding Interview》——第12章:测试——题目5·

    2014-04-25 00:41 题目:怎么测试一支笔?(Pen?您老说的是钢笔?) 解法:这种简约而不简单的题目,实在是面试官最喜欢,面试者最头疼的类型了.面试官可以只花三秒,以一种灰常高贵冷艳的语 ...

  9. 《Cracking the Coding Interview》——第12章:测试——题目4

    2014-04-25 00:35 题目:没有专门的测试工具,你要如何对一个网页进行压力测试? 解法:拼手速,拼电脑数量呗.快捷键+复制粘贴网址,狂搞一番.话说回来,有脚本语言的情况下,直接写个脚本来模 ...

随机推荐

  1. API:Sign签名的执行流程

    Sign签名存在目的:为了防止不法分子修改参数数据,进而攻击服务器,导致数据泄露或从中获得利益    例如:一个接口是用户把积分转帐给他的朋友,修改后,变为转帐到攻击者的帐户,这样,攻击者就能得到利益 ...

  2. COGS2287 [HZOI 2015]疯狂的机器人

    [题目描述] 现在在二维平面内原点上有一只机器人 他每次操作可以选择向右走,向左走,向下走,向上走和不走(每次如果走只能走一格) 但是由于本蒟蒻施展的大魔法,机器人不能走到横坐标是负数或者纵坐标是负数 ...

  3. LA 3635 派

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  4. 线程 task pritce

    1.使用task类创建并执行简单任务: 使用task的构造函数来创建 任务,并调用start方法来启动任务,执行异步操作 aitAll用于等待提供的所有 System.Threading.Tasks. ...

  5. P2082 区间覆盖(加强版)

    题目 #include<iostream> #include<algorithm> #include<cstring> using namespace std; s ...

  6. laravel 去掉index.php伪静态

    1,首先,让apache服务器支持rewrite 可以在apache配置文件中定义rewrite规则,是全局的,无论哪个应用都实用 //httpd.config Listen 80 RewriteEn ...

  7. SVN中Commit出现乱码的解决方案【转载】

    http://blog.csdn.net/thinkingcao/article/details/52797737 这几天在电脑上装了一个SVN,把Eclipse里面的工程全部Delete掉了,然后在 ...

  8. Oracle_11g中解决被锁定的scott用户的方法

    在安装完Oracle10g和创建完oracle数据库之后,想用数据库自带的用户scott登录,看看连接是否成功. 问题: 在cmd命令中,用“sqlplus  scott/ tiger”登录时,老是提 ...

  9. tcl之正则表达式

  10. PHP处理mysql事务

    MYSQL的事务处理主要有两种方法.1.用begin,rollback,commit来实现begin 开始一个事务rollback 事务回滚commit 事务确认2.直接用set来改变mysql的自动 ...