// Hint: This doesn't need to be a sophisticated data structure at // all, but if any of your tests are taking longer than a second, // that's a sign that you probably want to keep exploring // different approaches.
bool _error{}; //!< Flag indicating that the stream suffered an error.
//! \param[in] len bytes will be copied from the output side of the buffer string ByteStream::peek_output(constsize_t len)const{ return buffer.substr(0, len); }
//! \param[in] len bytes will be removed from the output side of the buffer voidByteStream::pop_output(constsize_t len){ buffer.erase(0, len); read_count += len; }
//! Read (i.e., copy and then pop) the next "len" bytes of the stream //! \param[in] len bytes will be popped and returned //! \returns a string std::string ByteStream::read(constsize_t len){ string output = buffer.substr(0, len); pop_output(len); // 在pop_output的时候会计算读取,这里不需要再+=len return output; }
Test Failure on expectation: Expectation: bytes_written: 3
Failure message: The ByteStream should have had bytes_written equal to 3 but instead it was 0
List of steps that executed successfully: Initialized with (capacity=15) Action: write "cat" to the stream Expectation: input_ended: 0 Expectation: buffer_empty: 0 Expectation: eof: 0 Expectation: bytes_read: 0