Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

rebuilt Ccoordinates class to normal form, added tests for coordinates

  • Loading branch information...
commit dc66bf23a37ef274f6ed0f482198c6b4c9acb9db 1 parent c29e01c
Daniel (dmilith) Dettlaff authored
View
11 coordinates.cpp
@@ -18,6 +18,17 @@ Ccoordinates::Ccoordinates() {
strcpy( parent_positions[ 4 ], generate_sha1().c_str() );
strcpy( parent_positions[ 5 ], generate_sha1().c_str() );
}
+
+char*
+Ccoordinates::get_parent_position( uint8_t element_ ) {
+ if ( element_ > 5 ) return NULL; // idiotouser check
+ return parent_positions[ element_ ];
+}
+
+char*
+Ccoordinates::get_position() {
+ return position;
+}
/*
Ccoordinates::Ccoordinates( char pos[SHA1_SIZE], char parent_pos[SHA1_SIZE][ 6 ] ) {
View
13 coordinates.h
@@ -15,11 +15,16 @@
static const uint8_t SHA1_SIZE = 41; // 40 + \0
class Ccoordinates {
-public:
- Ccoordinates();
+ private:
+ char position[SHA1_SIZE]; // sha1 as map location identifier
+ char parent_positions[6][SHA1_SIZE]; // sha1 z sha sąsiadujących elementów liczone od lewego boku 6 kąta
+
+ public:
+ Ccoordinates();
// Ccoordinates( char pos[SHA1_SIZE], char parent_pos[SHA1_SIZE][ 6 ] );
- char position[SHA1_SIZE]; // sha1 as map location identifier
- char parent_positions[6][SHA1_SIZE]; // sha1 z sha sąsiadujących elementów liczone od lewego boku 6 kąta
+
+ char* get_parent_position( uint8_t element_ );
+ char* get_position();
};
#endif //_CCOORDINATES_H_
View
5 tests/core/corechief.cpp
@@ -52,10 +52,7 @@ main( int argc, char** argv ) {
cout << "object core [1], after reloading with object[0] " << object_list[1].get_id() << endl << flush;
for ( int i = 0; i < 6; i++ ) {
- for ( int j = 0; j < 40; j++ ) {
- cout << object_list[1].get_position().parent_positions[i][j];
- }
- cout << endl;
+ cout << object_list[1].get_position().get_parent_position( i ) << endl;
}
cout << "Cobject size: " << sizeof( Cobject ) << endl << flush;
View
16 tests/other/coordinates_test.cpp
@@ -8,17 +8,15 @@ using namespace std;
int main() {
Ccoordinates position;
-
- cout << position.position << endl;
- assert ( sizeof( position.position ) == 41 );
-
+ cout << position.get_position() << endl << strlen( position.get_position() ) << endl;
+ assert( strlen( position.get_position() ) == 40 );
+ cout << position.get_parent_position( 5 ) << endl;
for ( int i = 0; i < 6; i++ ) {
- for ( int j = 0; j < 40; j++ ) {
- cout << position.parent_positions[i][j];
- }
- cout << endl;
+ assert( strlen( position.get_parent_position( i ) ) == 40 );
}
-
+ cout << position.get_parent_position( 6 ) << endl;
+ cout << position.get_position();
return 0;
}
+
View
2  tests/other/serialization_test.cpp
@@ -89,7 +89,7 @@ int main() {
//std::cout << "z: " << newg.items[0]->weight << std::endl;
//std::cout << "p: " << newg.private_box[0]->weight << std::endl;
for ( int i = 0; i < 6; ++i ) {
- std::cout << i << ": " << position.parent_positions[ i ] << std::endl;
+ std::cout << i << ": " << position.get_parent_position( i ) << std::endl;
}
// newg.items.begin();
Please sign in to comment.
Something went wrong with that request. Please try again.