Skip to content

Commit

Permalink
Merge pull request #56 from ufrshubham/testing_istream
Browse files Browse the repository at this point in the history
Added test for istream.
  • Loading branch information
ayaankhan98 authored Oct 10, 2020
2 parents 5b90a3a + 3a6caa0 commit 19a6c78
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tests/operators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ foreach(testsourcefile ${TEST_SOURCES})
add_test(${testname} ${testname})
endforeach()

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/input.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/input.txt)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/input.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
15 changes: 1 addition & 14 deletions tests/operators/input.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
1
100
10000
100000000
10000000000000000
100000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000
99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-10000000000000000000000000
-1122178617862763873649236587264782365872467823
-149023932491
-34873298478923748973289476592365782689523657926958326459823659726598237503297598246583657924628934928357891
-26589237985678256786763278562876389472836578264892365427961
1,100,10000,100000000,10000000000000000,100000000000000000000000000000000,100000000000000000000000000000000000000000000000000000000000000000,99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999,1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,-10000000000000000000000000,-1122178617862763873649236587264782365872467823,-149023932491,-34873298478923748973289476592365782689523657926958326459823659726598237503297598246583657924628934928357891,-26589237985678256786763278562876389472836578264892365427961
31 changes: 31 additions & 0 deletions tests/operators/istream_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <cassert>
#include <fstream>
#include <iostream>
#include <sstream>

#include <bigint.hpp>

int main()
{
std::ifstream f("input.txt");
std::string line;

if (f.is_open())
{
while (std::getline(f, line, ','))
{
std::stringstream buffer;
libbig::largeInt a;

buffer << line;
buffer >> a;
assert(a == libbig::largeInt(line));
buffer.str(std::string());
}
f.close();
} else {
throw std::runtime_error("Couldn't open input.txt");
}

return 0;
}
2 changes: 1 addition & 1 deletion tests/operators/ostream_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main()

if (f.is_open())
{
while (std::getline(f, line))
while (std::getline(f, line, ','))
{
a = libbig::largeInt(line);
buffer << a;
Expand Down

0 comments on commit 19a6c78

Please sign in to comment.