// file: $isip/class/search/HierarchicalSearch/hsrch_02.cc
// version: $Id: hsrch_02.cc 10594 2006-08-08 20:38:19Z ss754 $
//

// isip include files
//
#include "HierarchicalSearch.h"
#include <Console.h>

// method: diagnose
//
// arguments:
//  Integral::DEBUG level: (input) debug level for diagnostics
//
// return: logical error status
//
// this is the diagnostics method
//
boolean HierarchicalSearch::diagnose(Integral::DEBUG level_a) {

  //----------------------------------------------------------------------
  //
  // 0. preliminaries
  //
  //----------------------------------------------------------------------

  // output the class name
  //
  if (level_a > Integral::NONE) {
    SysString output(L"diagnosing class ");
    output.concat(CLASS_NAME);
    output.concat(L": ");
    Console::put(output);
    Console::increaseIndention();
  }

  //---------------------------------------------------------------------
  //
  // 1. required public methods
  //
  //---------------------------------------------------------------------


  // set indentation
  //
  if (level_a > Integral::NONE) {
    Console::put(L"testing required public methods...\n");
    Console::increaseIndention();
  }

  // declare variables
  //
  HierarchicalSearch hsrch_00;

  // test the get/set methods
  //
  hsrch_00.setSearchMode(HierarchicalSearch::TRAIN);
  
  if (hsrch_00.getSearchMode() != HierarchicalSearch::TRAIN) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }
 
  hsrch_00.setSearchMode(HierarchicalSearch::DECODE);
  
  if (hsrch_00.getSearchMode() != HierarchicalSearch::DECODE) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  hsrch_00.setInitialLevel(2);
  
  if (hsrch_00.getInitialLevel() != 2) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  hsrch_00.setInitialLevel(1);
  
  if (hsrch_00.getInitialLevel() != 1) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  long num_levels;
  
  HierarchicalDigraph h_digraph;
  Filename h_digraph_name;
  h_digraph_name.assign(L"h_digraph.sof"); 
  
  Sof h_digraph_file;
  h_digraph_file.open(h_digraph_name, File::READ_ONLY);
  h_digraph.read(h_digraph_file, (long)0);
  h_digraph_file.close();
  
  hsrch_00.setHDigraph(h_digraph);
  
  num_levels = hsrch_00.getNumLevels();
  hsrch_00.setNumLevels(num_levels);
  
  if (hsrch_00.getNumLevels() != num_levels) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  hsrch_00.setContextLevel(2);
  
  if (hsrch_00.getContextLevel() != 2) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  hsrch_00.setContextLevel(1);
  
  if (hsrch_00.getContextLevel() != 1) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }
  
  Vector<String> cont_list(3);

  cont_list(0).assign(L"S_1");
  cont_list(1).assign(L"S_2");
  cont_list(2).assign(L"S_3");

  hsrch_00.setContextList(cont_list);

  if (!hsrch_00.getContextList().eq(cont_list)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }  
  
  // reset indentation
  //
  if (level_a > Integral::NONE) {
    Console::decreaseIndention();
  }

  //---------------------------------------------------------------------
  //
  // 2. class-specific public methods
  //
  //---------------------------------------------------------------------

  // set indentation
  //
  if (level_a > Integral::NONE) {
    Console::put(L"testing class-specific public methods...\n");
    Console::increaseIndention(); 
  }

  // reset indentation
  //
  if (level_a > Integral::NONE) {
    Console::decreaseIndention();
  }
  
  //---------------------------------------------------------------------
  //
  // 4. print completion message
  //
  //---------------------------------------------------------------------

  // reset indentation
  //
  if (level_a > Integral::NONE) {
    Console::decreaseIndention();
  }
  
  if (level_a > Integral::NONE) {
    SysString output(L"diagnostics passed for class");
    output.concat(name());
    output.concat(L"\n");
    Console::put(output);
  }  

  // exit gracefully
  //
  return true;
}
