File tree Expand file tree Collapse file tree 7 files changed +33
-23
lines changed
StandardLibraryEssentials/StandardTemplateLibrary Expand file tree Collapse file tree 7 files changed +33
-23
lines changed Original file line number Diff line number Diff line change 33#include < iomanip>
44
55bool isNumber (const std::string& token) {
6- if (token.empty ()) {
6+ if (token.empty () || (token. size () == 1 && token[ 0 ] == ' - ' ) ) {
77 return false ;
88 }
99 int dotCount = 0 ;
1010 int minusCount = 0 ;
11- for (char c : token) {
11+ for (size_t i = 0 ; i < token.size (); ++i) {
12+ char c = token[i];
1213 if (c == ' .' ) {
13- if (dotCount > 0 ) {
14+ if (dotCount > 0 || i == 0 || (i == 1 && token[ 0 ] == ' - ' ) || i == token. size () - 1 ) {
1415 return false ;
1516 }
1617 dotCount++;
1718 }
1819 else if (c == ' -' ) {
19- if (minusCount > 0 || token[ 0 ] != ' - ' ) {
20+ if (minusCount > 0 || i != 0 ) {
2021 return false ;
2122 }
2223 minusCount++;
Original file line number Diff line number Diff line change 1010 length : 57
1111 placeholder_text : /* TODO */
1212 - offset : 105
13- length : 513
13+ length : 660
1414 placeholder_text : /* TODO */
15- - offset : 648
15+ - offset : 795
1616 length : 393
1717 placeholder_text : /* TODO */
1818 - name : test/test.cpp
Original file line number Diff line number Diff line change @@ -29,6 +29,20 @@ TEST(streamReaderTester, IsNumberTest) {
2929 ASSERT_TRUE (isNumber (" 123.456" ));
3030 ASSERT_TRUE (isNumber (" -123" ));
3131 ASSERT_TRUE (isNumber (" -123.456" ));
32+ ASSERT_FALSE (isNumber (" 123." ));
33+ ASSERT_FALSE (isNumber (" .123" ));
34+ ASSERT_FALSE (isNumber (" 123.456.789" ));
35+ ASSERT_FALSE (isNumber (" 123-456" ));
36+ ASSERT_FALSE (isNumber (" 123-" ));
37+ ASSERT_FALSE (isNumber (" -123-" ));
38+ ASSERT_FALSE (isNumber (" -123-456" ));
39+ ASSERT_FALSE (isNumber (" -.123" ));
40+ ASSERT_FALSE (isNumber (" -" ));
41+ ASSERT_FALSE (isNumber (" ." ));
42+ ASSERT_FALSE (isNumber (" " ));
43+ ASSERT_FALSE (isNumber (" -." ));
44+ ASSERT_FALSE (isNumber (" a" ));
45+ ASSERT_FALSE (isNumber (" a123" ));
3246}
3347
3448TEST (streamReaderTester, BiggerInput) {
Original file line number Diff line number Diff line change 11#ifndef CPPBASICS_ITERATOR_H
22#define CPPBASICS_ITERATOR_H
33
4+ #include < iostream>
5+ #include < vector>
6+
47class VectorIterator {
58public:
69 using pointer = int *;
Original file line number Diff line number Diff line change 1- #include < iostream>
2- #include < vector>
3- #include < algorithm>
41#include " ../include/iterator.h"
52
63VectorIterator::VectorIterator (pointer ptr) {
Original file line number Diff line number Diff line change 66 - name : src/task.cpp
77 visible : true
88 placeholders :
9- - offset : 143
9+ - offset : 84
1010 length : 11
1111 placeholder_text : /* TODO */
12- - offset : 224
12+ - offset : 165
1313 length : 13
1414 placeholder_text : /* TODO */
15- - offset : 300
15+ - offset : 241
1616 length : 12
1717 placeholder_text : /* TODO */
18- - offset : 367
18+ - offset : 308
1919 length : 25
2020 placeholder_text : /* TODO */
21- - offset : 449
21+ - offset : 390
2222 length : 58
2323 placeholder_text : /* TODO */
24- - offset : 562
24+ - offset : 503
2525 length : 25
2626 placeholder_text : /* TODO */
27- - offset : 644
27+ - offset : 585
2828 length : 58
2929 placeholder_text : /* TODO */
30- - offset : 778
30+ - offset : 719
3131 length : 24
3232 placeholder_text : /* TODO */
33- - offset : 879
33+ - offset : 820
3434 length : 24
3535 placeholder_text : /* TODO */
3636 - name : test/test.cpp
Original file line number Diff line number Diff line change @@ -40,31 +40,26 @@ int main() {
4040 int n = 10 ;
4141 int x = 5 ;
4242
43- // Create and fill the vector
4443 std::vector<int > vec = create_and_fill (n);
4544 std::cout << " After create_and_fill: " ;
4645 for (int i : vec) std::cout << i << ' ' ;
4746 std::cout << ' \n ' ;
4847
49- // Shuffle the vector
5048 shuffle_vector (vec);
5149 std::cout << " After shuffle_vector: " ;
5250 for (int i : vec) std::cout << i << ' ' ;
5351 std::cout << ' \n ' ;
5452
55- // Sort the vector in descending order
5653 sort_descending (vec);
5754 std::cout << " After sort_descending: " ;
5855 for (int i : vec) std::cout << i << ' ' ;
5956 std::cout << ' \n ' ;
6057
61- // Reverse the vector
6258 reverse_vector (vec);
6359 std::cout << " After reverse_vector: " ;
6460 for (int i : vec) std::cout << i << ' ' ;
6561 std::cout << ' \n ' ;
6662
67- // Find the value x in the vector
6863 auto it = find_value (vec, x);
6964 if (it != vec.end ()) {
7065 std::cout << " After find_value: Found " << x << " at position " << std::distance (vec.begin (), it) << ' \n ' ;
You can’t perform that action at this time.
0 commit comments