Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write all the TEST_F Gtest code in the test.cpp. And then find three bugs in the arraylist.h file. Thank you! ER DITORS 1 UNSAVED

image text in transcribedPlease write all the TEST_F Gtest code in the test.cpp.
image text in transcribed And then find three bugs in the arraylist.h file. Thank you!
image text in transcribed
image text in transcribed
ER DITORS 1 UNSAVED 1 cpp M M test.cpp part Citest.cpp part2 Carraylist. x clib.cpp part2> C arraylisth > ts ArrayList >get(int) const 1 Sifndef ABRAYLIST 2 #define HAYLIST JI 3 4 class ArrayList 5 public ArrayList(): 7 ArrayList(); 8 9 10 Returns the size of the list 11 12 int size () consti 13 14 15 Add an int to the last position in the array. If the new array size is bigger than the capacity, resize. (Default capacity - 5) est.cpp 12 rayoth arraylist.o Makefile tepp 1 void add (const int & val) 19 20 21 23 / Insert an int to a certain position, and shift everything backwards. If the position is invalid, does not do anything. If the new array size is bigger than the capacity, resize by 1. (Default capacity - 5) e/ void insert (int position, const int & val) / 28 29 30 31 32 33 34 35 Renoves an int from the position, and shift everyting in place Calling remove(2) on 1 2 3 4 5 results in 12451 The size also decrecents. If the position is invalid, does not do anything. void remove(int position) Replaces an int at the position with the new int. If the position is invalid, does not do anything. / void set (int position, const int & vali 48 41 /s > OUTLINE TIMELINE Returns the int that's at the position specified Returns unexpected result if the position isn't valid - 30 ensure it 13. 45 S 1 UNSAVED part2 > C arraylist.h> ArrayList>get(int) const void insert (int position, const int & val); M Removes an int from the position, and shift everyting in place Calling renove(2) on 1 2 3 4 5 1 results in | 1 2 4 5 The size also decrements. If the position is invalid, does not do anything. 3, M void remove(int position); 1 3, M 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 Replaces an int at the position with the new int. If the position is invalid, does not do anything. vold set (int position, const int & val); /** Returns the int that's at the position specified Returns unexpected result if the position isn't valid - so ensure it is. */ Int& get (int position); Int const & get (int position) const protected: void resize(); into array: int capacity; // defaults to 5 private: int size fendit I CORER NEDITORS 1 UNSAVED 4 an fib.cpp fib.h Makefile test.cpp part2 araylist arraylist.o Makefile LOOP 2.M test.cpp parti test.cpp part2. Carraylist.h fib.cpp part2 > test.cpp > TEST F(ArrayListTest, SetoffNominal) 1 Binclude "arrayList.h" 2 include atest/gtest.hu 3 class ArrayListTest i public testing :: Test { 5 protected: 6 // You can remove any or all of the following functions if its body is enpty. 3 ArrayListTest() { 9 // You can do set-up work for each test here. 10 > 11 12 virtual ArrayListTest() { // You can do clean-up work that doesn't throw exceptions here. 14 > 15 16 // If the constructor and destructor are not enough for setting up 17 // and cleaning up each test, you can define the following methods: virtual vold Setup() { 19 // Code here will be called immediately after the constructor (right 20 // before each test). 21 List.add( 1); 22 List.add(2); 23 List.add(3), 28 29 30 31 32 33 virtual vold Teardown() { // Code here will be called inmediately after each test (right // before the destructor). > // Objects declared here can be used by all tests in the test case. ArrayList List: > 35 36 37 38 39 40 41 42 43 TEST F(ArrayListTest, Getioninal) { // Exepet eth element to be 1, Ist elent to be 2, etc. for (int 1.11 31 1++) { EXPECT_2011. 1, list.get()) > > TEST F(ArrayList Test, Addominat) { // ... OUTLINE EXPLORER 20 OPEN EDITORS TUNSAVED LADA v porn fib.cpp C fibh M Makefile testapp v part2 Carlith arraylist.o M Makefile test.cpp part test.cpp part2 Carraylist.h fib.cpp pert2 > test.cpp > TEST F(ArrayListTest, SetOffNominal) LEIUL LUGLOF. 29 } 30 31 // objects declared here can be used by all tests in the fest case. 32 ArrayList list: 33 }; 34 35 TEST_F(Arraylist Test, GetNominal) { 36 // Exepet oth element to be 1, Ist elennt to be 2, etc. for (int i 0; 1 C arraylisth > ts ArrayList >get(int) const 1 Sifndef ABRAYLIST 2 #define HAYLIST JI 3 4 class ArrayList 5 public ArrayList(): 7 ArrayList(); 8 9 10 Returns the size of the list 11 12 int size () consti 13 14 15 Add an int to the last position in the array. If the new array size is bigger than the capacity, resize. (Default capacity - 5) est.cpp 12 rayoth arraylist.o Makefile tepp 1 void add (const int & val) 19 20 21 23 / Insert an int to a certain position, and shift everything backwards. If the position is invalid, does not do anything. If the new array size is bigger than the capacity, resize by 1. (Default capacity - 5) e/ void insert (int position, const int & val) / 28 29 30 31 32 33 34 35 Renoves an int from the position, and shift everyting in place Calling remove(2) on 1 2 3 4 5 results in 12451 The size also decrecents. If the position is invalid, does not do anything. void remove(int position) Replaces an int at the position with the new int. If the position is invalid, does not do anything. / void set (int position, const int & vali 48 41 /s > OUTLINE TIMELINE Returns the int that's at the position specified Returns unexpected result if the position isn't valid - 30 ensure it 13. 45 S 1 UNSAVED part2 > C arraylist.h> ArrayList>get(int) const void insert (int position, const int & val); M Removes an int from the position, and shift everyting in place Calling renove(2) on 1 2 3 4 5 1 results in | 1 2 4 5 The size also decrements. If the position is invalid, does not do anything. 3, M void remove(int position); 1 3, M 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 Replaces an int at the position with the new int. If the position is invalid, does not do anything. vold set (int position, const int & val); /** Returns the int that's at the position specified Returns unexpected result if the position isn't valid - so ensure it is. */ Int& get (int position); Int const & get (int position) const protected: void resize(); into array: int capacity; // defaults to 5 private: int size fendit I CORER NEDITORS 1 UNSAVED 4 an fib.cpp fib.h Makefile test.cpp part2 araylist arraylist.o Makefile LOOP 2.M test.cpp parti test.cpp part2. Carraylist.h fib.cpp part2 > test.cpp > TEST F(ArrayListTest, SetoffNominal) 1 Binclude "arrayList.h" 2 include atest/gtest.hu 3 class ArrayListTest i public testing :: Test { 5 protected: 6 // You can remove any or all of the following functions if its body is enpty. 3 ArrayListTest() { 9 // You can do set-up work for each test here. 10 > 11 12 virtual ArrayListTest() { // You can do clean-up work that doesn't throw exceptions here. 14 > 15 16 // If the constructor and destructor are not enough for setting up 17 // and cleaning up each test, you can define the following methods: virtual vold Setup() { 19 // Code here will be called immediately after the constructor (right 20 // before each test). 21 List.add( 1); 22 List.add(2); 23 List.add(3), 28 29 30 31 32 33 virtual vold Teardown() { // Code here will be called inmediately after each test (right // before the destructor). > // Objects declared here can be used by all tests in the test case. ArrayList List: > 35 36 37 38 39 40 41 42 43 TEST F(ArrayListTest, Getioninal) { // Exepet eth element to be 1, Ist elent to be 2, etc. for (int 1.11 31 1++) { EXPECT_2011. 1, list.get()) > > TEST F(ArrayList Test, Addominat) { // ... OUTLINE EXPLORER 20 OPEN EDITORS TUNSAVED LADA v porn fib.cpp C fibh M Makefile testapp v part2 Carlith arraylist.o M Makefile test.cpp part test.cpp part2 Carraylist.h fib.cpp pert2 > test.cpp > TEST F(ArrayListTest, SetOffNominal) LEIUL LUGLOF. 29 } 30 31 // objects declared here can be used by all tests in the fest case. 32 ArrayList list: 33 }; 34 35 TEST_F(Arraylist Test, GetNominal) { 36 // Exepet oth element to be 1, Ist elennt to be 2, etc. for (int i 0; 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Support For Data Mining Applications Discovering Knowledge With Inductive Queries Lnai 2682

Authors: Rosa Meo ,Pier L. Lanzi ,Mika Klemettinen

2004th Edition

3540224793, 978-3540224792

More Books

Students also viewed these Databases questions