我必须写自己的容器任务Linked_list和Array_list.我有一个接口:
typedef int value_type;
class Container
{
public:
class Iterator
{
public:
Iterator();
Iterator(value_type* other);
Iterator(const Iterator& other);
Iterator& operator=(const Iterator& other);
...
};
Container();
Container(const Container& other);
~Container();
virtual value_type& front() const=0;
virtual value_type& back() const=0;
virtual Iterator begin() const=0; //
...
};
Run Code Online (Sandbox Code Playgroud)
我做了派生类Linked_list和Array_list:
class Linked_list:public Container
{
public:
long int cur_size;
List elem;
static Link end_;
class Iterator: public Container::Iterator
{
friend Linked_list;
Link *p;
};
Iterator begin() const; //overriding virtual function return type …Run Code Online (Sandbox Code Playgroud) 我需要为不是由我编写的小型学习计划编写测试(使用谷歌测试框架).(这只是一个小型控制台游戏,可以从命令行获取模式或只是在运行时获取它)有一个问题:我无法更改源代码,但几乎所有方法都使用cout和cin.我的问题是"如何在测试时回答programm的请求(cin)(比如从字符串获取cin的数据)? ".
我有这个代码:
Socket incomingConnection = serverSocket.accept();
String strategy = "1";
Client client = new Client(incomingConnection, this, strategy);
Run Code Online (Sandbox Code Playgroud)
客户构造函数:
public Client(Socket socket, ChatServer chatServer, String strategy) throws IOException{
this.socket = socket;
this.inputStream = socket.getInputStream();
this.outputStream = socket.getOutputStream();
this.chatServer = chatServer;
this.instance1 = new Strategy1(chatServer, this);
this.instance2 = new Strategy2(chatServer, this);
this.strategy = (this.instance1.getName().equals(strategy1) ? this.instance1 : this.instance2);
this.strategy.setStreams();
}
Run Code Online (Sandbox Code Playgroud)
现在看起来像Strategy1:
public class Strategy1{
public Strategy1(ChatServer server, Client client) throws IOException{
this.chatServer = server;
this.client = client;
}
public void …Run Code Online (Sandbox Code Playgroud) c++ ×2
abstract ×1
cin ×1
inheritance ×1
java ×1
java-io ×1
nested ×1
sockets ×1
unit-testing ×1