// file: $isip/class/pr/LanguageModelIHD/lm_00.cc
//

// ISIP include files
//
#include "LanguageModelIHD.h"

// method: diagnose
//
// arguments:
//  Integral::DEBUG level: (input) debug level for diagnostics
//
// return: a boolean value indicating status
//
boolean LanguageModelIHD::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 indention
  //
  if (level_a > Integral::NONE) {
    Console::put(L"testing required public methods...\n");
    Console::increaseIndention();
  }
  
  // test constructor
  //
  LanguageModelIHD lmihd;
  
  if (level_a > Integral::BRIEF) {
    Console::put(L"testing debug method...");
    lmihd.debug(L"debug");
  }
  
  // load grammar file
  //
  Filename model_file_a;
  model_file_a.assign(L"diagnose_grammar_ihd.sof"); 

  Sof lm_file;
  
  lm_file.open(model_file_a, File::READ_ONLY);
  
  // test read method
  //
  if (level_a > Integral::BRIEF) {
    Console::put(L"testing read method...");
  }
    
  if(!lmihd.read(lm_file,0)) {
    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);
  }

  lm_file.close();    

  LanguageModelIHD lmihd2;

  // test other methods
  //
  lmihd2.setIHD(lmihd.getIHD());
  lmihd2.setRuleModel(lmihd.getRuleModel());
  if (level_a > Integral::BRIEF) {
    Console::put(L"testing other methods...");
  }

  
  // test write method
  //
  if (level_a > Integral::BRIEF) {
    Console::put(L"testing write method...");
  }

  Sof lm_file2;
  Filename model_file_a2(L"diagnose_grammar_ihd_output.sof");

  lm_file2.open(model_file_a2, File::WRITE_ONLY);

  if(!lmihd2.write(lm_file2,0)) {
    return Error::handle(name(), L"write", Error::TEST, __FILE__, __LINE__);
  }

  lm_file2.close();
  
  // test clear method
  //
  lmihd2.clear();

  if (level_a > Integral::BRIEF) {
    Console::put(L"testing clear method...");
  }

  // test assign
  //
  lmihd2.assign(lmihd);
  if (level_a > Integral::BRIEF) {
    Console::put(L"testing assign method...");
  }
  
  
  // test eq method
  //
  if (level_a > Integral::BRIEF) {
    Console::put(L"testing eq method...");
  }
  
  if(!lmihd2.eq(lmihd)) {
    return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__);
  }
  
  // reset indention
  //
  if (level_a > Integral::NONE) {
    Console::decreaseIndention();
  }
  
  //--------------------------------------------------------------------------
  //
  // 2. public i/o methods:
  //
  //--------------------------------------------------------------------------

  // read and write methods are tested above the assign and eq test method
  //

  // public other methods are tested after the testing read method
  //
  
  //--------------------------------------------------------------------------
  //
  // 3. Clean up.
  //
  //--------------------------------------------------------------------------

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

  // indicate success
  //
  return true;
}
