Commit cca36e16 authored by Jesse Mapel's avatar Jesse Mapel
Browse files

Modified TrackingTable to start at valid min for unsigned integer

parent f1d32bfd
Loading
Loading
Loading
Loading
+40 −31
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include "FileName.h"
#include "IException.h"
#include "Pvl.h"
#include "SpecialPixel.h"
#include "Table.h"
#include "TableField.h"
#include "TableRecord.h"
@@ -111,7 +112,7 @@ namespace Isis {

      fileNameField = m_fileList[i].first.name();
      serialNumberField = m_fileList[i].second;
      indexField = i;
      indexField = (int) (i + VALID_MINUI4);

      TableRecord record;
      record += fileNameField;
@@ -133,13 +134,21 @@ namespace Isis {
  * @returns FileName The FileName at the index specified
  */
  FileName TrackingTable::indexToFileName(unsigned int index) {
    if (index >= (unsigned int)m_fileList.size()) {
    if (index < VALID_MINUI4) {
      QString msg = "Cannot convert index [" + toString(index)
                  + "] to a filename, index is below valid minimum ["
                  + toString(VALID_MINUI4) + "].";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }

    unsigned int shiftedIndex = index - VALID_MINUI4;
    if (shiftedIndex >= (unsigned int)m_fileList.size()) {
      QString msg = "Cannot convert index [" + toString(index)
                  + "] to a filename, index is out of bounds.";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }

    return m_fileList[index].first;
    return m_fileList[shiftedIndex].first;
  }


@@ -153,14 +162,14 @@ namespace Isis {
  unsigned int TrackingTable::fileNameToIndex(FileName file, QString serialNumber) {
    for (int i = 0; i < m_fileList.size(); i++) {
      if (m_fileList[i].first == file) {
        return i;
        return i + VALID_MINUI4;
      }
    }

    // At this point, the file is not in the internal file list so append it
    // and return its new index.
    m_fileList.append(QPair<FileName, QString>(file, serialNumber));
    return m_fileList.size() - 1;
    return m_fileList.size() - 1 + VALID_MINUI4;
  }

}
+12 −11
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ namespace Isis {
   * @author 2018-07-19 Jesse Mapel & Summer Stapleton
   *
   * @internal
   *   @history 2018-07-26 Jesse Mapel - Added offset based on minimum unsigned integer value.
   */
  class TrackingTable{

+17 −17
Original line number Diff line number Diff line
@@ -12,29 +12,29 @@ Third record : fileName3.dat, 456789
TrackingTable object created

Testing the indexToFileName method ...
FileName at index 0: fileName1.cub
FileName at index 1: fileName2.cub
FileName at index 2: fileName3.dat
FileName at index 3 does not exist and an exception is thrown.
**PROGRAMMER ERROR** Cannot convert index [3] to a filename, index is out of bounds.
FileName at index 3: fileName1.cub
FileName at index 4: fileName2.cub
FileName at index 5: fileName3.dat
FileName at index 6 does not exist and an exception is thrown.
**PROGRAMMER ERROR** Cannot convert index [6] to a filename, index is out of bounds.

Testing the fileNameToIndex method ...
Index of FileName fileName1.cub: 0
Index of FileName fileName2.cub: 1
Index of FileName fileName3.cub: 2
Index of the non-existent FileName fileName4.cub (demonstrating its addition): 3
Index of FileName fileName1.cub: 3
Index of FileName fileName2.cub: 4
Index of FileName fileName3.cub: 5
Index of the non-existent FileName fileName4.cub (demonstrating its addition): 6

Testing the toTable method ...
First record : fileName1.cub, 1234567890
Second record: fileName2.cub, 123
Third record : fileName3.dat, 456789
Fourth record: fileName4.cub, 12345678901234567890
First record : fileName1.cub, 1234567890, 3
Second record: fileName2.cub, 123, 4
Third record : fileName3.dat, 456789, 5
Fourth record: fileName4.cub, 12345678901234567890, 6

Creating a new TrackingTable object with the table returned from toTable method ...
New TrackingTable object created

Testing that the Table returned from toTable on new TrackingTable matches ...
First record : fileName1.cub, 1234567890
Second record: fileName2.cub, 123
Third record : fileName3.dat, 456789
Fourth record: fileName4.cub, 12345678901234567890
First record : fileName1.cub, 1234567890, 3
Second record: fileName2.cub, 123, 4
Third record : fileName3.dat, 456789, 5
Fourth record: fileName4.cub, 12345678901234567890, 6
+72 −56
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ int main(int argc, char *argv[]) {

    cout << "Testing the indexToFileName method ..." << endl;

    for (int i = 0; i < 4; i++) {
    for (int i = 3; i < 7; i++) {
      try {
        cout << "FileName at index " << i << ": " << trackingTable2.indexToFileName(i).name() << endl;
      }
@@ -101,10 +101,18 @@ int main(int argc, char *argv[]) {

    Table tableOut2 = trackingTable2.toTable();

    cout << "First record : " << QString(tableOut2[0][0]) << ", " << QString(tableOut2[0][1]) << endl;
    cout << "Second record: " << QString(tableOut2[1][0]) << ", " << QString(tableOut2[1][1]) << endl;
    cout << "Third record : " << QString(tableOut2[2][0]) << ", " << QString(tableOut2[2][1]) << endl;
    cout << "Fourth record: " << QString(tableOut2[3][0]) << ", " << QString(tableOut2[3][1]) << endl;
    cout << "First record : " << QString(tableOut2[0][0]) << ", "
                              << QString(tableOut2[0][1]) << ", "
                              << int(tableOut2[0][2]) << endl;
    cout << "Second record: " << QString(tableOut2[1][0]) << ", "
                              << QString(tableOut2[1][1]) << ", "
                              << int(tableOut2[1][2]) << endl;
    cout << "Third record : " << QString(tableOut2[2][0]) << ", "
                              << QString(tableOut2[2][1]) << ", "
                              << int(tableOut2[2][2]) << endl;
    cout << "Fourth record: " << QString(tableOut2[3][0]) << ", "
                              << QString(tableOut2[3][1]) << ", "
                              << int(tableOut2[3][2]) << endl;

    cout << endl;

@@ -122,10 +130,18 @@ int main(int argc, char *argv[]) {

    Table tableOut3 = trackingTable3.toTable();

    cout << "First record : " << QString(tableOut3[0][0]) << ", " << QString(tableOut3[0][1]) << endl;
    cout << "Second record: " << QString(tableOut3[1][0]) << ", " << QString(tableOut3[1][1]) << endl;
    cout << "Third record : " << QString(tableOut3[2][0]) << ", " << QString(tableOut3[2][1]) << endl;
    cout << "Fourth record: " << QString(tableOut3[3][0]) << ", " << QString(tableOut3[3][1]) << endl;
    cout << "First record : " << QString(tableOut3[0][0]) << ", "
                              << QString(tableOut3[0][1]) << ", "
                              << int(tableOut3[0][2]) << endl;
    cout << "Second record: " << QString(tableOut3[1][0]) << ", "
                              << QString(tableOut3[1][1]) << ", "
                              << int(tableOut3[1][2]) << endl;
    cout << "Third record : " << QString(tableOut3[2][0]) << ", "
                              << QString(tableOut3[2][1]) << ", "
                              << int(tableOut3[2][2]) << endl;
    cout << "Fourth record: " << QString(tableOut3[3][0]) << ", "
                              << QString(tableOut3[3][1]) << ", "
                              << int(tableOut3[3][2]) << endl;

  }
  catch (IException &e) {