text:
namespace KBase
{

using std::cout;
using std::endl;
using std::flush;
using std::get;
using std::tuple;

// JAH 20160728 added KTable class constructor
KTable::KTable(unsigned int ID, const string &name, const string &SQL, unsigned int grpID)
{
  tabID = ID;
  tabName = name;
  tabSQL = SQL;
  tabGrpID = grpID;
}

KTable::~KTable() {};

// --------------------------------------------

void Model::demoSQLite()
{
  cout << endl << "Starting basic demo of SQLite in Model class" << endl;

  auto callBack = [](void *data, int numCol, char **stringFields, char **colNames)
  {
    for (int i = 0; i < numCol; i++)
    {
      printf("%s = %s\n", colNames[i], stringFields[i] ? stringFields[i] : "NULL");
    }
    printf("\n");
    return ((int)0);
  };

  sqlite3 *db = nullptr;
  char* zErrMsg = nullptr;
  int  rc;
  string sql;

  auto sOpen = [&db](unsigned int n)
  {
    int rc = sqlite3_open("test.db", &db);
    if (rc != SQLITE_OK)
    {
      fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
      exit(0);
    }
    else
    {
      fprintf(stderr, "Opened database successfully (%i)\n", n);
    }
    return;
  };

  auto sExec = [callBack, &db, &zErrMsg](string sql, string msg)
  {
    int rc = sqlite3_exec(db, sql.c_str(), callBack, nullptr, &zErrMsg); // nullptr is the 'data' argument
    if (rc != SQLITE_OK)
    {
      fprintf(stderr, "SQL error: %s\n", zErrMsg);
      sqlite3_free(zErrMsg);
    }
    else
    {
      fprintf(stdout, msg.c_str());
    }
    return rc;
  };

  // Open database
  cout << endl << flush;
  sOpen(1);

  // try some pragmas. these should speed up operations on larger tables,
  // at the expense of making the table vulnerable to corruption if the
  // application abruptly terminates mid-operation.
  sql = "PRAGMA synchronous = off;";
  rc = sExec(sql, "Set synchronous to off \n");

  sql = "PRAGMA journal_mode = off;";
  rc = sExec(sql, "Set journal_mode to off \n");

  sql = "PRAGMA locking_mode = exclusive;";
  rc = sExec(sql, "Set locking_mode to exclusive \n");

  // Create SQL statement
  sql = "create table if not exists PETS("  \
        "ID INT PRIMARY KEY     NOT NULL," \
        "NAME           text    NOT NULL," \
        "AGE            int     NOT NULL," \
        "BREED         char(50)," \
        "COLOR         char(50) );";

  // Execute SQL statement
  rc = sExec(sql, "Created table successfully \n");
  sqlite3_close(db);

  cout << endl << flush;
  sOpen(2);

  // This SQL statement has one deliberate error.
  sql = "INSERT INTO PETS (ID, NAME, AGE, BREED, COLOR) "   \
        "VALUES (1, 'Alice', 6, 'Greyhound', 'Grey' ); "    \
        "INSERT INTO PETS (ID, NAME, AGE, BREED, COLOR) "   \
        "VALUES (2, 'Bob', 4, 'Newfoundland', 'Black' ); "  \
        "INSERT INTO PETS (ID, NAME, AGE, BREED, COLOR) "   \
        "VALUES (3, 'Carol', 7, 'Chihuahua', 'Tan' );"      \
        "INSERT INTO PETS (ID, NAME, AGE, SPECIES, COLOR) " \
        "VALUES (4, 'David', 5, 'Alsation', 'Mixed' );";
  \
  "INSERT INTO PETS (ID, NAME, AGE, SPECIES, COLOR) " \
  "VALUES (5, 'Ellie', 8, 'Rhodesian', 'Red' );";

  cout << "NB: This should get one planned SQL error at ID=4" << endl << flush;
  rc = sExec(sql, "Records inserted successfully \n");
  sqlite3_close(db);

  cout << endl << flush;
  sOpen(3);
  sql = "SELECT * from PETS where AGE>5;";
  rc = sExec(sql, "Records selected successfully\n");
  cout << "NB: ID=5 was never inserted due to planned SQL error at ID=4" << endl;
  sqlite3_close(db);

  cout << endl << flush;
  sOpen(4);
  sql = "DROP TABLE PETS;";
  rc = sExec(sql, "Dropped table successfully \n");
  sqlite3_close(db);

  return;
}

bool testMultiThreadSQLite (bool tryReset, KBase::ReportingLevel rl) {
  int mutexP = sqlite3_threadsafe() ;
  bool parP = (0 != mutexP);
  if (ReportingLevel::Silent < rl) {
    if (parP) {
      cout << "This SQLite3 library WAS compiled to be threadsafe."<<endl << flush;
    } else {
      cout << "This SQLite3 library was NOT compiled to be threadsafe."<<endl << flush;
    }
  }
  if (tryReset && (!parP)) {
    int configRslt = sqlite3_config(SQLITE_CONFIG_SERIALIZED);
    if (configRslt == SQLITE_OK) {
      parP = true;
    }
    else  {
      parP = false;
    }
    if (ReportingLevel::Low < rl){
      cout << "  Note that multi-threading might have been disabled via sqlite3_config."<<endl<<flush;
      cout << "  Tried to reconfigure to SQLITE_CONFIG_SERIALIZED ... " << flush;
      if (configRslt == SQLITE_OK) {
        cout << "SUCCESS"<< endl;
      }
      else  {
        cout << "FAILED"<< endl;
      }
    }
  }
  if (ReportingLevel::Silent < rl) {
    if (parP)  {
      cout << "Possible to continue multi-threaded"<< endl << flush;
    }
    else {
      cout << "Necessary to continue single-threaded"<< endl << flush;
    }
  }
  return parP;
}

// note that the function to write to table #k must be kept
// synchronized with the result of createSQL(k) !
// JAH 20160728 modified to return a KTable object instead of the SQL string
KTable * Model::createSQL(unsigned int n)
{

  string sql = "";
  string name = "";
  unsigned int grpID = 0;

  assert(n < Model::NumTables);
  switch (n)
  {
  case 0:
    // position-utility table
    // the estimated utility to each actor of each other's position
    sql = "create table if not exists PosUtil ("  \
          "ScenarioId TEXT(32) NOT NULL DEFAULT 'None', "\
          "Turn_t	INTEGER NOT NULL DEFAULT 0, "\
          "Est_h	INTEGER NOT NULL DEFAULT 0, "\
          "Act_i	INTEGER NOT NULL DEFAULT 0, "\
          "Pos_j	INTEGER NOT NULL DEFAULT 0, "\
          "Util	REAL NOT NULL DEFAULT 0.0"\
          ");";
    name = "PosUtil";
    grpID = 4;
    break;

  case 1: // pos-vote table
    // estimated vote of each actor between each pair of positions
    sql = "create table if not exists PosVote ("  \
          "ScenarioId TEXT(32) NOT NULL DEFAULT 'None', "\
          "Turn_t	INTEGER NOT NULL DEFAULT 0, "\
          "Est_h	INTEGER NOT NULL DEFAULT 0, "\
          "Voter_k	INTEGER NOT NULL DEFAULT 0, "\
          "Pos_i	INTEGER NOT NULL DEFAULT 0, "\
          "Pos_j	INTEGER NOT NULL DEFAULT 0, "\
          "Vote	REAL NOT NULL DEFAULT 0.0"\
          ");";
    name = "PosVote";
    grpID = 1;
    break;

  case 2: // pos-prob table. Note that there may be duplicates, unless we limit it to unique positions
    sql = "create table if not exists PosProb ("  \
          "ScenarioId TEXT(32) NOT NULL DEFAULT 'None', "\
          "Turn_t	INTEGER NOT NULL DEFAULT 0, "\
          "Est_h	INTEGER NOT NULL DEFAULT 0, "\
          "Pos_i	INTEGER NOT NULL DEFAULT 0, "\
          "Prob	REAL NOT NULL DEFAULT 0.0"\
          ");";
    name = "PosProb";
    grpID = 1;
    break;

  case 3: // pos-equiv table. E(i)= lowest j s.t. Pos(i) ~ Pos(j). if j < i, it is not unique.
    sql = "create table if not exists PosEquiv ("  \
          "ScenarioId TEXT(32) NOT NULL DEFAULT 'None', "\
          "Turn_t	INTEGER NOT NULL DEFAULT 0, "\
          "Pos_i	INTEGER NOT NULL DEFAULT 0, "\
          "Eqv_j	INTEGER NOT NULL DEFAULT 0 "\
          ");";
    name = "PosEquiv";
    grpID = 1;
    break;

  case 4:
    // h's estimate of the utility to k of i challenging j, preceded by intermediate values
    // U{^h}{_k} ( SQ ), current status quo positions
    // U{^h}{_k} ( i >  j ), i defeats j
    // U{^h}{_k} ( i :  j ), contest between i and j
    // U{^h}{_k} ( i => j ), i challenges j
    // Utilities are evaluated so that UtilSQ, UtilVict, UtilChlg, UtilContest,
    // UtilTPVict, UtilTPLoss are comparable, i.e. the differences are meaningful
    sql = "create table if not exists UtilChlg ("  \
          "ScenarioId TEXT(32) NOT NULL DEFAULT 'none', "\
          "Turn_t	INTEGER NOT NULL DEFAULT 0, "\
          "Est_h	INTEGER NOT NULL DEFAULT 0, "\
          "Aff_k	INTEGER NOT NULL DEFAULT 0, "\
          "Init_i	INTEGER NOT NULL DEFAULT 0, "\
          "Rcvr_j	INTEGER NOT NULL DEFAULT 0, "\
          "Util_SQ	   	REAL    NOT NULL DEFAULT 0, "\
          "Util_Vict	REAL    NOT NULL DEFAULT 0, "\
          "Util_Cntst	REAL    NOT NULL DEFAULT 0, "\
          "Util_Chlg	REAL    NOT NULL DEFAULT 0  "\
          ");";
    name = "UtilChlg";
    grpID = 2;
    break;

  case 5:
    // h's estimate that i will defeat j, including all third party contributions
    // P{^h}( i > j )
    sql = "create table if not exists ProbVict ("  \
          "ScenarioId TEXT(32) NOT NULL DEFAULT 'None', "\
          "Turn_t	INTEGER NOT NULL DEFAULT 0, "\
          "Est_h	INTEGER NOT NULL DEFAULT 0, "\
          "Init_i	INTEGER NOT NULL DEFAULT 0, "\
          "Rcvr_j	INTEGER NOT NULL DEFAULT 0, "\
          "Prob	REAL NOT NULL DEFAULT 0"\
          ");";
    name = "PosVict";
    grpID = 2;
    break;

  case 6:
    // h's estimates in a little 3-actor contest with no contribution from others:
    // P{^h}( ik > j )      probability ik defeats j,
    // U{^h}{_k} (ik > j)   utility to k of winning with i, over j
    // U{^h}{_k} (i > jk)   utility to k of losing to i, with j
    sql = "create table if not exists TP_Prob_Vict_Loss ("  \
          "ScenarioId TEXT(32) NOT NULL DEFAULT 'None', "\
          "Turn_t	INTEGER NOT NULL DEFAULT 0, "\
          "Est_h	INTEGER NOT NULL DEFAULT 0, "\
          "Init_i	INTEGER NOT NULL DEFAULT 0, "\
          "ThrdP_k	INTEGER NOT NULL DEFAULT 0, "\
          "Rcvr_j	INTEGER NOT NULL DEFAULT 0, "\
          "Prob	REAL    NOT NULL DEFAULT 0, "\
          "Util_V	REAL    NOT NULL DEFAULT 0, "\
          "Util_L	REAL    NOT NULL DEFAULT 0  "\
          ");";
    name = "TP_Prob_Vict_Loss";
    grpID = 2;
    break;

  case 7:   // short-name and long-description of actors
  {
    char *sqlBuff = newChars(500);
    sprintf(sqlBuff, "create table if not exists ActorDescription ("  \
                     "ScenarioId TEXT(32) NOT NULL DEFAULT 'None', "\
                     "Act_i	INTEGER NOT NULL DEFAULT 0, "\
                     "Name	TEXT(%u) NOT NULL DEFAULT 'NoName', "\
                     "Desc	TEXT(%u) NOT NULL DEFAULT 'NoName' "\
                     ");", maxActNameLen, maxActDescLen);
    sql = std::string(sqlBuff);
    delete sqlBuff;
    sqlBuff = nullptr;
    name = "ActorDescription";
    grpID = 0;
  }
    break;

  case 8: // Bargain table
    sql = "create table if not exists Bargn ("  \
          "ScenarioId TEXT(32) NOT NULL DEFAULT 'None', "\
          "Turn_t	INTEGER NOT NULL DEFAULT 0, "\
          "BargnId INTEGER NOT NULL DEFAULT 0, "\
          "Init_Act_i INTEGER NOT NULL DEFAULT 0, "\
          "Recd_Act_j INTEGER NOT NULL DEFAULT 0, "\
          "Value REAL NOT NULL DEFAULT 0.0, "\
          "Init_Prob REAL NULL DEFAULT 0, "\
          "Init_Seld	BOOLEAN NULL ,"\
          "Recd_Prob REAL NULL DEFAULT 0, "\
          "Recd_Seld	BOOLEAN NULL"\
          ");";
    name = "Bargn";
    grpID = 4;
    break;
  case 9:  //
    // BargnCoords table
    sql = "create table if not exists BargnCoords ("  \
          "ScenarioId TEXT(32) NOT NULL DEFAULT 'None', "\
          "Turn_t	INTEGER NOT NULL DEFAULT 0, "\
          "BargnId INTEGER NOT NULL DEFAULT 0, "\
          "Dim_k INTEGER NOT NULL DEFAULT 0, "\
          "Init_Coord	REAL NULL DEFAULT 0.0,"\
          "Recd_Coord	REAL NOT NULL DEFAULT 0.0"\
          ");";
    name = "BargnCoords";
    grpID = 3;
    break;

  case 10:  // BargnUtil table creation
    sql = "create table if not exists BargnUtil ("  \
          "ScenarioId TEXT(32) NOT NULL DEFAULT 'None', "\
          "Turn_t	INTEGER NOT NULL DEFAULT 0, "\
          "BargnId    INTEGER NOT NULL	DEFAULT 0, "\
          "Act_i 	INTEGER NOT NULL DEFAULT 0, "\
          "Util	REAL NOT NULL DEFAULT 0.0"\
          ");";
    name = "BargnUtil";
    grpID = 3;
    break;

  case 11:
    // During bargain resolution, this table records the actual vote
    // of each actor between each pair of competing bargains
    sql = "create table if not exists BargnVote ("  \
          "ScenarioId TEXT(32) NOT NULL DEFAULT 'None', "\
          "Turn_t	INTEGER NOT NULL DEFAULT 0, "\
          "BargnId_i  INTEGER NOT NULL DEFAULT 0, "\
          "BargnId_j INTEGER NOT NULL DEFAULT 0, "\
          "Act_k 	INTEGER NOT NULL DEFAULT 0, "\
          "Vote	REAL NOT NULL DEFAULT 0.0"\
          ");";
    name = "BargnVote";
    grpID = 3;
    break;

  case 12:  //ScenarioDesc creation
    // JAH 20160711 added the RNGSeed field
    sql = "create table if not exists ScenarioDesc ("  \
          "Scenario TEXT(512) NOT NULL DEFAULT 'NoName', "\
          "Desc TEXT(512) NOT NULL DEFAULT 'No Description', "\
          "ScenarioId TEXT(32) NOT NULL UNIQUE DEFAULT 'None'," \
          "RNGSeed TEXT(20) NOT NULL DEFAULT '0'," \
          "VictoryProbModel INTEGER NULL DEFAULT NULL," \
          "ProbCondorcetElection INTEGER NULL DEFAULT NULL," \
          "StateTransition INTEGER NULL DEFAULT NULL," \
          "VotingRule INTEGER NULL DEFAULT NULL," \
          "BigRAdjust INTEGER NULL DEFAULT NULL," \
          "BigRRange INTEGER NULL DEFAULT NULL," \
          "ThirdPartyCommit INTEGER NULL DEFAULT NULL," \
          "InterVecBrgn INTEGER NULL DEFAULT NULL," \
          "BargnModel INTEGER NULL DEFAULT NULL" \
          ");";
    name = "ScenarioDesc";
    grpID = 0;
    break;
  default:
    throw(KException("Model::createTableSQL unrecognized table number"));
  }

  assert(grpID < NumSQLLogGrps);
  auto tab = new KTable(n,name,sql,grpID);
  return tab;
}

void Model::sqlAUtil(unsigned int t)
{
  assert(nullptr != smpDB);
  assert(t < history.size());
  State* st = history[t];
  assert(nullptr != st);
  assert(numAct == st->aUtil.size());

  // I don't like passing 'this' into lambda-functions,
  // so I copy the pointer into a local variable I can pass in
  // without exposing everything in 'this'. If this were a big,
  // mission-critical RDBMS, rather than a 1-off record of this run,
  // doing so might be disasterous in case the system crashed before
  // things were cleaned up.
  sqlite3 * db = smpDB;
  smpDB = nullptr;

  char* zErrMsg = nullptr;
  auto sqlBuff = newChars(200);
  sprintf(sqlBuff,
          "INSERT INTO PosUtil (ScenarioId, Turn_t, Est_h, Act_i, Pos_j, Util) VALUES ('%s', ?1, ?2, ?3, ?4, ?5)",
          scenId.c_str());

  assert(nullptr != db);
  const char* insStr = sqlBuff;
  sqlite3_stmt *insStmt;
  sqlite3_prepare_v2(db, insStr, strlen(insStr), &insStmt, NULL);
  // Prepared statements cache the execution plan for a query after the query optimizer has
  // found the best plan, so there is no big gain with simple insertions.
  // What makes a huge difference is bundling a few hundred into one atomic "transaction".
  // For this case, runtime droped from 62-65 seconds to 0.5-0.6 (vs. 0.30-0.33 with no SQL at all).
  assert(nullptr != insStmt); // make sure it is ready

  sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, &zErrMsg);
  for (unsigned int h = 0; h < numAct; h++)   // estimator is h
  {
    KMatrix uij = st->aUtil[h]; // utility to actor i of the position held by actor j
    for (unsigned int i = 0; i < numAct; i++)
    {
      for (unsigned int j = 0; j < numAct; j++)
      {
        int rslt = 0;
        rslt = sqlite3_bind_int(insStmt, 1, t);
        assert(SQLITE_OK == rslt);
        rslt = sqlite3_bind_int(insStmt, 2, h);
        assert(SQLITE_OK == rslt);
        rslt = sqlite3_bind_int(insStmt, 3, i);
        assert(SQLITE_OK == rslt);
        rslt = sqlite3_bind_int(insStmt, 4, j);
        assert(SQLITE_OK == rslt);
        rslt = sqlite3_bind_double(insStmt, 5, uij(i, j));
        assert(SQLITE_OK == rslt);
        rslt = sqlite3_step(insStmt);
        assert(SQLITE_DONE == rslt);
        sqlite3_clear_bindings(insStmt);
        assert(SQLITE_DONE == rslt);
        rslt = sqlite3_reset(insStmt);
        assert(SQLITE_OK == rslt);
      }
    }
  }
  sqlite3_exec(db, "END TRANSACTION", NULL, NULL, &zErrMsg);
  sqlite3_finalize(insStmt); // finalize statement to avoid resource leaks
  //printf("Stored SQL for turn %u of all estimators, actors, and positions \n", t);

  delete sqlBuff;
  sqlBuff = nullptr;

  smpDB = db; // give it the new pointer

  return;
}
// populates record for table PosEquiv for each step of
// module run
void Model::sqlPosEquiv(unsigned int t)
{
  // Check database intact
  assert(nullptr != smpDB);
  assert(t < history.size());
  State* st = history[t];
  assert(nullptr != st);
  sqlite3 * db = smpDB;
  smpDB = nullptr;
  // In case of error
  char* zErrMsg = nullptr;
  auto sqlBuff = newChars(200);
  sprintf(sqlBuff,
          "INSERT INTO PosEquiv (ScenarioId, Turn_t, Pos_i, Eqv_j) VALUES ('%s', ?1, ?2, ?3)",
          scenId.c_str());

  assert(nullptr != db);
  const char* insStr = sqlBuff;
  sqlite3_stmt *insStmt;
  sqlite3_prepare_v2(db, insStr, strlen(insStr), &insStmt, NULL);
  assert(nullptr != insStmt); // make sure it is ready

  // Start inserting record
  sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, &zErrMsg);
  for (unsigned int i = 0; i < numAct; i++)
  {
    // calculate the equivalance
    int je = numAct + 1;
    for (unsigned int j = 0; j < numAct && je > numAct; j++)
    {
      if (st->equivNdx(i, j))
      {
        je = j;
      }
    }
    int rslt = 0;
    rslt = sqlite3_bind_int(insStmt, 1, t);
    assert(SQLITE_OK == rslt);
    rslt = sqlite3_bind_int(insStmt, 2, i);
    assert(SQLITE_OK == rslt);
    rslt = sqlite3_bind_int(insStmt, 3, je);
    assert(SQLITE_OK == rslt);
    rslt = sqlite3_step(insStmt);
    assert(SQLITE_DONE == rslt);
    sqlite3_clear_bindings(insStmt);
    assert(SQLITE_DONE == rslt);
    rslt = sqlite3_reset(insStmt);
    assert(SQLITE_OK == rslt);
  }
  // end databse transaction
  sqlite3_exec(db, "END TRANSACTION", NULL, NULL, &zErrMsg);
  sqlite3_finalize(insStmt); // finalize statement to avoid resource leaks
  //printf("Stored SQL for turn %u of all estimators, actors, and positions \n", t);
  delete sqlBuff;
  sqlBuff = nullptr;
  smpDB = db;
  return;
}

void Model::sqlBargainEntries(unsigned int t, int bargainId, int initiator, int receiver, double val)
{
  // initiate the database
  sqlite3 * db = smpDB;

  // Error message in case
  char* zErrMsg = nullptr;
  auto sqlBuff = newChars(200);
  // prepare the sql statement to insert
  sprintf(sqlBuff,
          "INSERT INTO Bargn (ScenarioId, Turn_t, BargnID, Init_Act_i, Recd_Act_j,Value) VALUES ('%s',?1, ?2, ?3, ?4,?5)",
          scenId.c_str());

  assert(nullptr != db);
  const char* insStr = sqlBuff;
  sqlite3_stmt *insStmt;
  sqlite3_prepare_v2(db, insStr, strlen(insStr), &insStmt, NULL);
  assert(nullptr != insStmt); // make sure it is ready

  // start for the transaction
  sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, &zErrMsg);

  int rslt = 0;
  // Turn_t
  rslt = sqlite3_bind_int(insStmt, 1, t);
  assert(SQLITE_OK == rslt);
  //BargnID
  rslt = sqlite3_bind_int(insStmt, 2, bargainId);
  assert(SQLITE_OK == rslt);
  //Init_Act_i
  rslt = sqlite3_bind_int(insStmt, 3, initiator);
  assert(SQLITE_OK == rslt);
  //Recd_Act_j
  rslt = sqlite3_bind_int(insStmt, 4, receiver);
  assert(SQLITE_OK == rslt);
  //Value
  rslt = sqlite3_bind_double(insStmt, 5, val);
  assert(SQLITE_OK == rslt);
  rslt = sqlite3_step(insStmt);
  assert(SQLITE_DONE == rslt);
  sqlite3_clear_bindings(insStmt);
  assert(SQLITE_DONE == rslt);
  rslt = sqlite3_reset(insStmt);
  assert(SQLITE_OK == rslt);

  sqlite3_exec(db, "END TRANSACTION", NULL, NULL, &zErrMsg);
  //printf("Stored SQL for turn %u of all estimators, actors, and positions \n", t);
  sqlite3_finalize(insStmt); // finalize statement to avoid resource leaks
  delete sqlBuff;
  sqlBuff = nullptr;

  smpDB = db;
}

void Model::sqlBargainCoords(unsigned int t, int bargnID, const KBase::VctrPstn & initPos, const KBase::VctrPstn & rcvrPos)
{
  int nDim = initPos.numR();
  assert(nDim == rcvrPos.numR());

  // initiate the database
  sqlite3 * db = smpDB;
  // Error message in case
  char* zErrMsg = nullptr;
  auto sqlBuff = newChars(200);

  // prepare the sql statement to insert
  sprintf(sqlBuff,
          "INSERT INTO BargnCoords (ScenarioId, Turn_t,BargnId, Dim_k, Init_Coord,Recd_Coord) VALUES ('%s',?1, ?2, ?3, ?4,?5)",
          scenId.c_str());

  assert(nullptr != db);
  const char* insStr = sqlBuff;
  sqlite3_stmt *insStmt;
  sqlite3_prepare_v2(db, insStr, strlen(insStr), &insStmt, NULL);
  assert(nullptr != insStmt); // make sure it is ready

  // start for the transaction
  sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, &zErrMsg);

  for (int k = 0; k < nDim; k++)
  {

    int rslt = 0;
    // Turn_t
    rslt = sqlite3_bind_int(insStmt, 1, t);
    assert(SQLITE_OK == rslt);
    //Baragainer
    rslt = sqlite3_bind_int(insStmt, 2, bargnID);
    assert(SQLITE_OK == rslt);
    //Dim_K
    rslt = sqlite3_bind_int(insStmt, 3, k);
    assert(SQLITE_OK == rslt);

    //Init_Coord
    rslt = sqlite3_bind_double(insStmt, 4, initPos(k,0) * 100.0); // Log at the scale of [0,100]
    assert(SQLITE_OK == rslt);
    //Recd_Coord

    rslt = sqlite3_bind_double(insStmt, 5, rcvrPos(k, 0) * 100.0); // Log at the scale of [0,100]
    assert(SQLITE_OK == rslt);
    rslt = sqlite3_step(insStmt);
    assert(SQLITE_DONE == rslt);
    sqlite3_clear_bindings(insStmt);
    assert(SQLITE_DONE == rslt);
    rslt = sqlite3_reset(insStmt);
    assert(SQLITE_OK == rslt);

  }

  sqlite3_exec(db, "END TRANSACTION", NULL, NULL, &zErrMsg);
  sqlite3_finalize(insStmt); // finalize statement to avoid resource leaks
  delete sqlBuff;
  sqlBuff = nullptr;
  smpDB = db;
}

void Model::sqlBargainUtil(unsigned int t, vector<uint64_t> bargnIds,  KBase::KMatrix Util_mat)
{
  // initiate the database
  sqlite3 * db = smpDB;

  // Error message in case
  char* zErrMsg = nullptr;
  auto sqlBuff = newChars(200);

  int Util_mat_row = Util_mat.numR();
  int Util_mat_col = Util_mat.numC();

  // prepare the sql statement to insert
  sprintf(sqlBuff,
          "INSERT INTO BargnUtil  (ScenarioId, Turn_t,BargnId, Act_i, Util) VALUES ('%s',?1, ?2, ?3, ?4)",
          scenId.c_str());

  assert(nullptr != db);
  const char* insStr = sqlBuff;
  sqlite3_stmt *insStmt;
  sqlite3_prepare_v2(db, insStr, strlen(insStr), &insStmt, NULL);
  assert(nullptr != insStmt); // make sure it is ready
	// start for the transaction
	sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, &zErrMsg);
	uint64_t Bargn_i = 0;
    for (unsigned int i = 0; i < Util_mat_row; i++)
    {
		for (unsigned int j = 0; j < Util_mat_col; j++)
		{

			int rslt = 0;
			// Turn_t
			rslt = sqlite3_bind_int(insStmt, 1, t);
			assert(SQLITE_OK == rslt);
			//Bargn_i
			Bargn_i = bargnIds[j];
			rslt = sqlite3_bind_int(insStmt, 2, Bargn_i);
			assert(SQLITE_OK == rslt);
			//Act_i
			rslt = sqlite3_bind_int(insStmt, 3, i);
			assert(SQLITE_OK == rslt);
			//Util
			rslt = sqlite3_bind_double(insStmt, 4, Util_mat(i, j));
			assert(SQLITE_OK == rslt);
			// finish
			assert(SQLITE_OK == rslt);
			rslt = sqlite3_step(insStmt);
			assert(SQLITE_DONE == rslt);
			sqlite3_clear_bindings(insStmt);
			assert(SQLITE_DONE == rslt);
			rslt = sqlite3_reset(insStmt);
			assert(SQLITE_OK == rslt);
		}
	}

  sqlite3_exec(db, "END TRANSACTION", NULL, NULL, &zErrMsg);
  sqlite3_finalize(insStmt); // finalize statement to avoid resource leaks

  delete sqlBuff;
  sqlBuff = nullptr;

  smpDB = db;
}

// JAH 20160731 added this function in replacement to the separate
// populate* functions that separately logged information tables
// this only covers the general "Model" info tables; currently only Actors and Scenarios
void Model::LogInfoTables()
{
  int rslt = 0;
  // check the database availability
  sqlite3 * db = smpDB;
  assert(nullptr != smpDB);
  char* zErrMsg = nullptr;

  // assert tests for all tables here at the start
  assert(numAct == actrs.size());

  // for efficiency sake, we'll do all tables in a single transaction
  // form the insert cmmands
  auto sqlBuffA = newChars(sqlBuffSize);
  sprintf(sqlBuffA,"INSERT INTO ActorDescription (ScenarioId,Act_i,Name,Desc) VALUES ('%s', ?1, ?2, ?3)",
          scenId.c_str());
  auto sqlBuffS = newChars(sqlBuffSize);
  sprintf(sqlBuffS,"INSERT INTO ScenarioDesc (Scenario,Desc,ScenarioId,RNGSeed,"
      "VictoryProbModel,ProbCondorcetElection,StateTransition) VALUES ('%s',?1,?2,?3,?4,?5,?6)",
          scenName.c_str());
  // prepare the prepared statement statements
  sqlite3_stmt *insStmtA;
  sqlite3_prepare_v2(smpDB, sqlBuffA, strlen(sqlBuffA), &insStmtA, NULL);
  assert(nullptr != insStmtA);
  sqlite3_stmt *insStmtS;
  sqlite3_prepare_v2(smpDB, sqlBuffS, strlen(sqlBuffS), &insStmtS, NULL);
  assert(nullptr != insStmtS);

  sqlite3_exec(smpDB, "BEGIN TRANSACTION", NULL, NULL, &zErrMsg);

  // Actor Description Table
  // For each actor fill the required information
  for (unsigned int i = 0; i < actrs.size(); i++) {
    Actor * act = actrs.at(i);
    // bind the data
    rslt = sqlite3_bind_int(insStmtA, 1, i);
    assert(SQLITE_OK == rslt);
    rslt = sqlite3_bind_text(insStmtA, 2, act->name.c_str(), -1, SQLITE_TRANSIENT);
    assert(SQLITE_OK == rslt);
    rslt = sqlite3_bind_text(insStmtA, 3, act->desc.c_str(), -1, SQLITE_TRANSIENT);
    assert(SQLITE_OK == rslt);
    // record
    rslt = sqlite3_step(insStmtA);
    assert(SQLITE_DONE == rslt);
    sqlite3_clear_bindings(insStmtA);
    assert(SQLITE_DONE == rslt);
    rslt = sqlite3_reset(insStmtA);
    assert(SQLITE_OK == rslt);
  }

  // Scenario Description
  // Turn_t
  rslt = sqlite3_bind_text(insStmtS, 1, scenDesc.c_str(), -1, SQLITE_TRANSIENT);
  assert(SQLITE_OK == rslt);
  // Scen Id
  rslt = sqlite3_bind_text(insStmtS, 2, scenId.c_str(), -1, SQLITE_TRANSIENT);
  assert(SQLITE_OK == rslt);
  // rng seed JAH 20160711
  // have to convert to text and store it that way, since sqlite3 doesn't really understand unsigned ints
  char *seedBuff = newChars(50);
  sprintf(seedBuff,"%20llu",rngSeed);
  const char* strSeed = seedBuff;
  rslt = sqlite3_bind_text(insStmtS, 3, strSeed, -1, SQLITE_TRANSIENT);
  assert(SQLITE_OK == rslt);
  rslt = sqlite3_bind_int(insStmtS, 4, static_cast<int>(vpm));
  assert(SQLITE_OK == rslt);
  rslt = sqlite3_bind_int(insStmtS, 5, static_cast<int>(pcem));
  assert(SQLITE_OK == rslt);
  rslt = sqlite3_bind_int(insStmtS, 6, static_cast<int>(stm));
  assert(SQLITE_OK == rslt);
  // record
  assert(SQLITE_OK == rslt);
  rslt = sqlite3_step(insStmtS);
  assert(SQLITE_DONE == rslt);
  sqlite3_clear_bindings(insStmtS);
  assert(SQLITE_DONE == rslt);
  rslt = sqlite3_reset(insStmtS);
  assert(SQLITE_OK == rslt);

  // finish
  sqlite3_exec(db, "END TRANSACTION", NULL, NULL, &zErrMsg);
  // finalize statement to avoid resource leaks
  sqlite3_finalize(insStmtA);
  sqlite3_finalize(insStmtS);
  delete sqlBuffA;
  sqlBuffA = nullptr;
  delete sqlBuffS;
  sqlBuffS = nullptr;
  return;
}

void Model::sqlBargainVote(unsigned int t, vector< tuple<uint64_t, uint64_t>> barginidspair_i_j, vector<double> Vote_mat,unsigned int act_k)
{
	// initiate the database
	sqlite3 * db = smpDB;

	// Error message in case
	char* zErrMsg = nullptr;
	auto sqlBuff = newChars(200);

	int Util_mat_row = Vote_mat.size();
//	int Util_mat_col = Vote_mat[0].size();

	// prepare the sql statement to insert
	sprintf(sqlBuff,
		"INSERT INTO BargnVote  (ScenarioId, Turn_t,BargnId_i,  BargnId_j, Act_k, Vote) VALUES ('%s', ?1, ?2, ?3,?4,?5)",scenId.c_str());

    assert(nullptr != db);
	const char* insStr = sqlBuff;
	sqlite3_stmt *insStmt;
	sqlite3_prepare_v2(db, insStr, strlen(insStr), &insStmt, NULL);
    assert(nullptr != insStmt); //make sure it is ready

	// start for the transaction
	sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, &zErrMsg);

    for (unsigned int i = 0; i <Util_mat_row ; i++)
    {
		tuple<uint64_t, uint64_t> tijids = barginidspair_i_j[i];
		uint64_t Bargn_i = std::get<0>(tijids);
		uint64_t Bargn_j = std::get<1>(tijids);

//for (unsigned int j = 0; j <  Util_mat_col; j++)
//		{
			int rslt = 0;
			// Turn_t
			rslt = sqlite3_bind_int(insStmt, 1, t);
			assert(SQLITE_OK == rslt);
			//Bargn_i
			rslt = sqlite3_bind_int(insStmt, 2, Bargn_i);
			assert(SQLITE_OK == rslt);
			//Bargn_j
			rslt = sqlite3_bind_int(insStmt, 3, Bargn_j);
			assert(SQLITE_OK == rslt);
			//Act_i
			rslt = sqlite3_bind_int(insStmt, 4, act_k);
			assert(SQLITE_OK == rslt);
			//Util
			rslt = sqlite3_bind_double(insStmt, 5, Vote_mat[i]);
			assert(SQLITE_OK == rslt);
			// finish
			assert(SQLITE_OK == rslt);
			rslt = sqlite3_step(insStmt);
			assert(SQLITE_DONE == rslt);
			sqlite3_clear_bindings(insStmt);
			assert(SQLITE_DONE == rslt);
			rslt = sqlite3_reset(insStmt);
			assert(SQLITE_OK == rslt);
		//}
	}
	sqlite3_exec(db, "END TRANSACTION", NULL, NULL, &zErrMsg);
	sqlite3_finalize(insStmt); // finalize statement to avoid resource leaks

	delete sqlBuff;
	sqlBuff = nullptr;

	smpDB = db;
}

// populates record for table PosProb for each step of
// module run
void Model::sqlPosProb(unsigned int t)
{
  assert(nullptr != smpDB);
  assert(t < history.size());
  State* st = history[t];
  // check module for null
  assert(nullptr != st);
  // initiate the database
  sqlite3 * db = smpDB;
  smpDB = nullptr;
  // Error message in case
  char* zErrMsg = nullptr;
  auto sqlBuff = newChars(200);
  // prepare the sql statement to insert
  sprintf(sqlBuff,
          "INSERT INTO PosProb (ScenarioId, Turn_t, Est_h,Pos_i, Prob) VALUES ('%s', ?1, ?2, ?3, ?4)",
          scenId.c_str());
  const char* insStr = sqlBuff;

  assert(nullptr != db);
  sqlite3_stmt *insStmt;
  sqlite3_prepare_v2(db, insStr, strlen(insStr), &insStmt, NULL);
  assert(nullptr != insStmt); //make sure it is ready

  // start for the transaction
  sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, &zErrMsg);
  // collect the information from each estimator,actor
  for (unsigned int h = 0; h < numAct; h++)   // estimator is h
  {
    // calculate the probablity with respect to each estimator
    auto pn = st->pDist(h);
    auto pdt = std::get<0>(pn); // note that these are unique positions
    assert( fabs(1 - sum(pdt)) < 1e-4);
    auto unq = std::get<1>(pn);
    // for each actor pupulate the probablity information
    for (unsigned int i = 0; i < numAct; i++)
    {
      int rslt = 0;
      // Extract the probabity for each actor
      double prob = st->posProb(i, unq, pdt);
      rslt = sqlite3_bind_int(insStmt, 1, t);
      assert(SQLITE_OK == rslt);
      rslt = sqlite3_bind_int(insStmt, 2, h);
      assert(SQLITE_OK == rslt);
      rslt = sqlite3_bind_int(insStmt, 3, i);
      assert(SQLITE_OK == rslt);
      rslt = sqlite3_bind_double(insStmt, 4, prob);
      assert(SQLITE_OK == rslt);
      rslt = sqlite3_step(insStmt);
      assert(SQLITE_DONE == rslt);
      sqlite3_clear_bindings(insStmt);
      assert(SQLITE_DONE == rslt);
      rslt = sqlite3_reset(insStmt);
      assert(SQLITE_OK == rslt);
    }
  }
  sqlite3_exec(db, "END TRANSACTION", NULL, NULL, &zErrMsg);
  sqlite3_finalize(insStmt); // finalize statement to avoid resource leaks
  //printf("Stored SQL for turn %u of all estimators, actors, and positions \n", t);

  delete sqlBuff;
  sqlBuff = nullptr;

  smpDB = db; // give it the new pointer

  return;
}
// populates record for table PosProb for each step of
// module run
void Model::sqlPosVote(unsigned int t)
{
  assert(nullptr != smpDB);
  assert(t < history.size());
  State* st = history[t];

  // check module for null
  assert(nullptr != st);
  // initiate the database
  sqlite3 * db = smpDB;
  smpDB = nullptr;
  // Error message in case
  char* zErrMsg = nullptr;
  auto sqlBuff = newChars(200);
  // prepare the sql statement to insert
  sprintf(sqlBuff,
          "INSERT INTO PosVote (ScenarioId, Turn_t, Est_h, Voter_k,Pos_i, Pos_j,Vote) VALUES ('%s', ?1, ?2, ?3, ?4,?5,?6)",
          scenId.c_str());

  assert(nullptr != db);
  const char* insStr = sqlBuff;
  sqlite3_stmt *insStmt;
  sqlite3_prepare_v2(db, insStr, strlen(insStr), &insStmt, NULL);
  assert(nullptr != insStmt); //make sure it is ready

  // start for the transaction
  sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, &zErrMsg);
  auto vr = VotingRule::Proportional;
  // collect the information from each estimator

  for (unsigned int k = 0; k < numAct; k++)   // voter is k
  {
    auto rd = st->model->actrs[k];
    for (unsigned int i = 0; i < numAct; i++)
    {
      for (unsigned int j = 0; j < numAct; j++)
      {
        for (unsigned int h = 0; h < numAct; h++)   // estimator is h
        {
          if (((h == i) || (h == j)) && (i!=j))
          {
            auto vij = rd->vote(h, i, j, st);
            int rslt = 0;
            rslt = sqlite3_bind_int(insStmt, 1, t);
            assert(SQLITE_OK == rslt);
            rslt = sqlite3_bind_int(insStmt, 2, h);
            assert(SQLITE_OK == rslt);
            //voter_k
            rslt = sqlite3_bind_int(insStmt, 3, k);
            assert(SQLITE_OK == rslt);
            // position i
            rslt = sqlite3_bind_int(insStmt, 4, i);
            assert(SQLITE_OK == rslt);
            //position j
            rslt = sqlite3_bind_int(insStmt, 5, j);
            assert(SQLITE_OK == rslt);
            // vote ?
            rslt = sqlite3_bind_double(insStmt, 6, vij);
            assert(SQLITE_OK == rslt);
            rslt = sqlite3_step(insStmt);
            assert(SQLITE_DONE == rslt);
            sqlite3_clear_bindings(insStmt);
            assert(SQLITE_DONE == rslt);
            rslt = sqlite3_reset(insStmt);
            assert(SQLITE_OK == rslt);
          }
        }
      }
    }
  }
  sqlite3_exec(db, "END TRANSACTION", NULL, NULL, &zErrMsg);
  sqlite3_finalize(insStmt); // finalize statement to avoid resource leaks
  //printf("Stored SQL for turn %u of all estimators, actors, and positions \n", t);

  delete sqlBuff;
  sqlBuff = nullptr;

  smpDB = db; // give it the new pointer

  return;
}

void Model::createTableIndices() {
    char * zErrMsg = nullptr;
    const char * indexUtil = "CREATE INDEX IF NOT EXISTS idx_util ON PosUtil(ScenarioId, Turn_t, Est_h, Act_i, Pos_j)";
    int rc = sqlite3_exec(smpDB, indexUtil, nullptr, nullptr, &zErrMsg);
    assert(rc == SQLITE_OK);

    const char *indexActor = "CREATE INDEX IF NOT EXISTS idx_actor ON ActorDescription(ScenarioId)";
    rc = sqlite3_exec(smpDB, indexActor, nullptr, nullptr, &zErrMsg);
    assert(rc == SQLITE_OK);
}

void Model::dropTableIndices(){
    char * zErrMsg = nullptr;
    const char * indexUtil = "DROP INDEX IF EXISTS idx_util";
    int rc = sqlite3_exec(smpDB, indexUtil, nullptr, nullptr, &zErrMsg);

    assert(rc == SQLITE_OK);

    const char * indexActor = "DROP INDEX IF EXISTS idx_actor";
    rc = sqlite3_exec(smpDB, indexActor, nullptr, nullptr, &zErrMsg);
    assert(rc == SQLITE_OK);
}

} // end of namespace

// --------------------------------------------
// Copyright KAPSARC. Open source MIT License.
// --------------------------------------------


text:
interface IRectangle {
    height: number,
    width: number,
    getArea(): number
}

module App.Shapes {
    export class Rectangle implements IRectangle {
        constructor(public height: number, public width: number) {
        }

        getArea() : number {
            return this.height * this.width;
        }
    }

    export var rect: IRectangle = new Rectangle(10, 4);
}

// can't include module2.ts at runtime (i.e. module2.js) in Node
// so we have it here.
module App.Shapes {
    export class Circle {
        constructor(public radius: number) {
        }
    }
}

module myProgram {
    function run() {
        var myRectangle: App.Shapes.Rectangle = App.Shapes.rect;
        console.info(myRectangle.height, myRectangle.getArea());

        var yourRectangle = new App.Shapes.Rectangle(9,6);
        console.info(yourRectangle.height);

        var aCircle = new App.Shapes.Circle(5);
        console.info(aCircle.radius);
    }

    run();
}

module Program2 {
    import shapes = App.Shapes;

    function run() {
        var myRectangle: IRectangle = shapes.rect;
        console.info(myRectangle.height, myRectangle.getArea());

        var yourRectangle = new shapes.Rectangle(9,6);
        console.info(yourRectangle.height);
    }

    run();
}

redpajama_set_name: RedPajamaGithub


text:
namespace gfx {
class ImageSkia;
}

namespace ui {

// Includes information necessary about a network for displaying the appropriate
// UI to the user.
struct UI_CHROMEOS_EXPORT NetworkInfo {
  NetworkInfo();
  NetworkInfo(const std::string& path);
  ~NetworkInfo();

  std::string service_path;
  base::string16 label;
  base::string16 tooltip;
  gfx::ImageSkia image;
  bool disable;
  bool highlight;
};

}  // namespace ui

#endif  // UI_CHROMEOS_NETWORK_NETWORK_INFO_H_


text:
package proxy

import (
	"fmt"
	"io/ioutil"
	"net"
	"net/http"
	"net/http/httptest"
	"net/url"
	"strconv"
	"testing"
	"time"

	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
	"github.com/GoogleCloudPlatform/kubernetes/pkg/util/iptables"
)

func joinHostPort(host string, port int) string {
	return net.JoinHostPort(host, fmt.Sprintf("%d", port))
}

func waitForClosedPortTCP(p *Proxier, proxyPort int) error {
	for i := 0; i < 50; i++ {
		conn, err := net.Dial("tcp", joinHostPort("", proxyPort))
		if err != nil {
			return nil
		}
		conn.Close()
		time.Sleep(1 * time.Millisecond)
	}
	return fmt.Errorf("port %d still open", proxyPort)
}

func waitForClosedPortUDP(p *Proxier, proxyPort int) error {
	for i := 0; i < 50; i++ {
		conn, err := net.Dial("udp", joinHostPort("", proxyPort))
		if err != nil {
			return nil
		}
		conn.SetReadDeadline(time.Now().Add(10 * time.Millisecond))
		// To detect a closed UDP port write, then read.
		_, err = conn.Write([]byte("x"))
		if err != nil {
			if e, ok := err.(net.Error); ok && !e.Timeout() {
				return nil
			}
		}
		var buf [4]byte
		_, err = conn.Read(buf[0:])
		if err != nil {
			if e, ok := err.(net.Error); ok && !e.Timeout() {
				return nil
			}
		}
		conn.Close()
		time.Sleep(1 * time.Millisecond)
	}
	return fmt.Errorf("port %d still open", proxyPort)
}

// The iptables logic has to be tested in a proper end-to-end test, so this just stubs everything out.
type fakeIptables struct{}

func (fake *fakeIptables) EnsureChain(table iptables.Table, chain iptables.Chain) (bool, error) {
	return false, nil
}

func (fake *fakeIptables) FlushChain(table iptables.Table, chain iptables.Chain) error {
	return nil
}

func (fake *fakeIptables) EnsureRule(table iptables.Table, chain iptables.Chain, args ...string) (bool, error) {
	return false, nil
}

func (fake *fakeIptables) DeleteRule(table iptables.Table, chain iptables.Chain, args ...string) error {
	return nil
}

var tcpServerPort string
var udpServerPort string

func init() {
	// TCP setup.
	tcp := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
		w.Write([]byte(r.URL.Path[1:]))
	}))
	u, err := url.Parse(tcp.URL)
	if err != nil {
		panic(fmt.Sprintf("failed to parse: %v", err))
	}
	_, tcpServerPort, err = net.SplitHostPort(u.Host)
	if err != nil {
		panic(fmt.Sprintf("failed to parse: %v", err))
	}

	// UDP setup.
	udp, err := newUDPEchoServer()
	if err != nil {
		panic(fmt.Sprintf("failed to make a UDP server: %v", err))
	}
	_, udpServerPort, err = net.SplitHostPort(udp.LocalAddr().String())
	if err != nil {
		panic(fmt.Sprintf("failed to parse: %v", err))
	}
	go udp.Loop()
}

func testEchoTCP(t *testing.T, address string, port int) {
	path := "aaaaa"
	res, err := http.Get("http://" + address + ":" + fmt.Sprintf("%d", port) + "/" + path)
	if err != nil {
		t.Fatalf("error connecting to server: %v", err)
	}
	defer res.Body.Close()
	data, err := ioutil.ReadAll(res.Body)
	if err != nil {
		t.Errorf("error reading data: %v %v", err, string(data))
	}
	if string(data) != path {
		t.Errorf("expected: %s, got %s", path, string(data))
	}
}

func testEchoUDP(t *testing.T, address string, port int) {
	data := "abc123"

	conn, err := net.Dial("udp", joinHostPort(address, port))
	if err != nil {
		t.Fatalf("error connecting to server: %v", err)
	}
	if _, err := conn.Write([]byte(data)); err != nil {
		t.Fatalf("error sending to server: %v", err)
	}
	var resp [1024]byte
	n, err := conn.Read(resp[0:])
	if err != nil {
		t.Errorf("error receiving data: %v", err)
	}
	if string(resp[0:n]) != data {
		t.Errorf("expected: %s, got %s", data, string(resp[0:n]))
	}
}

func TestTCPProxy(t *testing.T) {
	lb := NewLoadBalancerRR()
	lb.OnUpdate([]api.Endpoints{
		{
			ObjectMeta: api.ObjectMeta{Name: "echo"},
			Endpoints:  []string{net.JoinHostPort("127.0.0.1", tcpServerPort)},
		},
	})

	p := NewProxier(lb, net.ParseIP("127.0.0.1"), &fakeIptables{})

	svcInfo, err := p.addServiceOnPort("echo", "TCP", 0, time.Second)
	if err != nil {
		t.Fatalf("error adding new service: %#v", err)
	}
	testEchoTCP(t, "127.0.0.1", svcInfo.proxyPort)
}

func TestUDPProxy(t *testing.T) {
	lb := NewLoadBalancerRR()
	lb.OnUpdate([]api.Endpoints{
		{
			ObjectMeta: api.ObjectMeta{Name: "echo"},
			Endpoints:  []string{net.JoinHostPort("127.0.0.1", udpServerPort)},
		},
	})

	p := NewProxier(lb, net.ParseIP("127.0.0.1"), &fakeIptables{})

	svcInfo, err := p.addServiceOnPort("echo", "UDP", 0, time.Second)
	if err != nil {
		t.Fatalf("error adding new service: %#v", err)
	}
	testEchoUDP(t, "127.0.0.1", svcInfo.proxyPort)
}

// Helper: Stops the proxy for the named service.
func stopProxyByName(proxier *Proxier, service string) error {
	info, found := proxier.getServiceInfo(service)
	if !found {
		return fmt.Errorf("unknown service: %s", service)
	}
	return proxier.stopProxy(service, info)
}

func TestTCPProxyStop(t *testing.T) {
	lb := NewLoadBalancerRR()
	lb.OnUpdate([]api.Endpoints{
		{
			ObjectMeta: api.ObjectMeta{Name: "echo"},
			Endpoints:  []string{net.JoinHostPort("127.0.0.1", tcpServerPort)},
		},
	})

	p := NewProxier(lb, net.ParseIP("127.0.0.1"), &fakeIptables{})

	svcInfo, err := p.addServiceOnPort("echo", "TCP", 0, time.Second)
	if err != nil {
		t.Fatalf("error adding new service: %#v", err)
	}
	conn, err := net.Dial("tcp", joinHostPort("", svcInfo.proxyPort))
	if err != nil {
		t.Fatalf("error connecting to proxy: %v", err)
	}
	conn.Close()

	stopProxyByName(p, "echo")
	// Wait for the port to really close.
	if err := waitForClosedPortTCP(p, svcInfo.proxyPort); err != nil {
		t.Fatalf(err.Error())
	}
}

func TestUDPProxyStop(t *testing.T) {
	lb := NewLoadBalancerRR()
	lb.OnUpdate([]api.Endpoints{
		{
			ObjectMeta: api.ObjectMeta{Name: "echo"},
			Endpoints:  []string{net.JoinHostPort("127.0.0.1", udpServerPort)},
		},
	})

	p := NewProxier(lb, net.ParseIP("127.0.0.1"), &fakeIptables{})

	svcInfo, err := p.addServiceOnPort("echo", "UDP", 0, time.Second)
	if err != nil {
		t.Fatalf("error adding new service: %#v", err)
	}
	conn, err := net.Dial("udp", joinHostPort("", svcInfo.proxyPort))
	if err != nil {
		t.Fatalf("error connecting to proxy: %v", err)
	}
	conn.Close()

	stopProxyByName(p, "echo")
	// Wait for the port to really close.
	if err := waitForClosedPortUDP(p, svcInfo.proxyPort); err != nil {
		t.Fatalf(err.Error())
	}
}

func TestTCPProxyUpdateDelete(t *testing.T) {
	lb := NewLoadBalancerRR()
	lb.OnUpdate([]api.Endpoints{
		{
			ObjectMeta: api.ObjectMeta{Name: "echo"},
			Endpoints:  []string{net.JoinHostPort("127.0.0.1", tcpServerPort)},
		},
	})

	p := NewProxier(lb, net.ParseIP("127.0.0.1"), &fakeIptables{})

	svcInfo, err := p.addServiceOnPort("echo", "TCP", 0, time.Second)
	if err != nil {
		t.Fatalf("error adding new service: %#v", err)
	}
	conn, err := net.Dial("tcp", joinHostPort("", svcInfo.proxyPort))
	if err != nil {
		t.Fatalf("error connecting to proxy: %v", err)
	}
	conn.Close()

	p.OnUpdate([]api.Service{})
	if err := waitForClosedPortTCP(p, svcInfo.proxyPort); err != nil {
		t.Fatalf(err.Error())
	}
}

func TestUDPProxyUpdateDelete(t *testing.T) {
	lb := NewLoadBalancerRR()
	lb.OnUpdate([]api.Endpoints{
		{
			ObjectMeta: api.ObjectMeta{Name: "echo"},
			Endpoints:  []string{net.JoinHostPort("127.0.0.1", udpServerPort)},
		},
	})

	p := NewProxier(lb, net.ParseIP("127.0.0.1"), &fakeIptables{})

	svcInfo, err := p.addServiceOnPort("echo", "UDP", 0, time.Second)
	if err != nil {
		t.Fatalf("error adding new service: %#v", err)
	}
	conn, err := net.Dial("udp", joinHostPort("", svcInfo.proxyPort))
	if err != nil {
		t.Fatalf("error connecting to proxy: %v", err)
	}
	conn.Close()

	p.OnUpdate([]api.Service{})
	if err := waitForClosedPortUDP(p, svcInfo.proxyPort); err != nil {
		t.Fatalf(err.Error())
	}
}

func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
	lb := NewLoadBalancerRR()
	lb.OnUpdate([]api.Endpoints{
		{
			ObjectMeta: api.ObjectMeta{Name: "echo"},
			Endpoints:  []string{net.JoinHostPort("127.0.0.1", tcpServerPort)},
		},
	})

	p := NewProxier(lb, net.ParseIP("127.0.0.1"), &fakeIptables{})

	svcInfo, err := p.addServiceOnPort("echo", "TCP", 0, time.Second)
	if err != nil {
		t.Fatalf("error adding new service: %#v", err)
	}
	conn, err := net.Dial("tcp", joinHostPort("", svcInfo.proxyPort))
	if err != nil {
		t.Fatalf("error connecting to proxy: %v", err)
	}
	conn.Close()

	p.OnUpdate([]api.Service{})
	if err := waitForClosedPortTCP(p, svcInfo.proxyPort); err != nil {
		t.Fatalf(err.Error())
	}
	p.OnUpdate([]api.Service{
		{ObjectMeta: api.ObjectMeta{Name: "echo"}, Spec: api.ServiceSpec{Port: svcInfo.proxyPort, Protocol: "TCP", ProxyPort: svcInfo.proxyPort}, Status: api.ServiceStatus{}},
	})
	testEchoTCP(t, "127.0.0.1", svcInfo.proxyPort)
}

func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
	lb := NewLoadBalancerRR()
	lb.OnUpdate([]api.Endpoints{
		{
			ObjectMeta: api.ObjectMeta{Name: "echo"},
			Endpoints:  []string{net.JoinHostPort("127.0.0.1", udpServerPort)},
		},
	})

	p := NewProxier(lb, net.ParseIP("127.0.0.1"), &fakeIptables{})

	svcInfo, err := p.addServiceOnPort("echo", "UDP", 0, time.Second)
	if err != nil {
		t.Fatalf("error adding new service: %#v", err)
	}
	conn, err := net.Dial("udp", joinHostPort("", svcInfo.proxyPort))
	if err != nil {
		t.Fatalf("error connecting to proxy: %v", err)
	}
	conn.Close()

	p.OnUpdate([]api.Service{})
	if err := waitForClosedPortUDP(p, svcInfo.proxyPort); err != nil {
		t.Fatalf(err.Error())
	}
	p.OnUpdate([]api.Service{
		{ObjectMeta: api.ObjectMeta{Name: "echo"}, Spec: api.ServiceSpec{Port: svcInfo.proxyPort, Protocol: "UDP", ProxyPort: svcInfo.proxyPort}, Status: api.ServiceStatus{}},
	})
	testEchoUDP(t, "127.0.0.1", svcInfo.proxyPort)
}

func TestTCPProxyUpdatePort(t *testing.T) {
	lb := NewLoadBalancerRR()
	lb.OnUpdate([]api.Endpoints{
		{
			ObjectMeta: api.ObjectMeta{Name: "echo"},
			Endpoints:  []string{net.JoinHostPort("127.0.0.1", tcpServerPort)},
		},
	})

	p := NewProxier(lb, net.ParseIP("127.0.0.1"), &fakeIptables{})

	svcInfo, err := p.addServiceOnPort("echo", "TCP", 0, time.Second)
	if err != nil {
		t.Fatalf("error adding new service: %#v", err)
	}

	// add a new dummy listener in order to get a port that is free
	l, _ := net.Listen("tcp", ":0")
	_, newPortStr, _ := net.SplitHostPort(l.Addr().String())
	newPort, _ := strconv.Atoi(newPortStr)
	l.Close()

	// Wait for the socket to actually get free.
	if err := waitForClosedPortTCP(p, newPort); err != nil {
		t.Fatalf(err.Error())
	}
	if svcInfo.proxyPort == newPort {
		t.Errorf("expected difference, got %d %d", newPort, svcInfo.proxyPort)
	}
	p.OnUpdate([]api.Service{
		{ObjectMeta: api.ObjectMeta{Name: "echo"}, Spec: api.ServiceSpec{Port: newPort, Protocol: "TCP", ProxyPort: newPort}, Status: api.ServiceStatus{}},
	})
	if err := waitForClosedPortTCP(p, svcInfo.proxyPort); err != nil {
		t.Fatalf(err.Error())
	}
	testEchoTCP(t, "127.0.0.1", newPort)

	// Ensure the old port is released and re-usable.
	l, err = net.Listen("tcp", joinHostPort("", svcInfo.proxyPort))
	if err != nil {
		t.Fatalf("can't claim released port: %s", err)
	}
	l.Close()
}

func TestUDPProxyUpdatePort(t *testing.T) {
	lb := NewLoadBalancerRR()
	lb.OnUpdate([]api.Endpoints{
		{
			ObjectMeta: api.ObjectMeta{Name: "echo"},
			Endpoints:  []string{net.JoinHostPort("127.0.0.1", udpServerPort)},
		},
	})

	p := NewProxier(lb, net.ParseIP("127.0.0.1"), &fakeIptables{})

	svcInfo, err := p.addServiceOnPort("echo", "UDP", 0, time.Second)
	if err != nil {
		t.Fatalf("error adding new service: %#v", err)
	}

	// add a new dummy listener in order to get a port that is free
	pc, _ := net.ListenPacket("udp", ":0")
	_, newPortStr, _ := net.SplitHostPort(pc.LocalAddr().String())
	newPort, _ := strconv.Atoi(newPortStr)
	pc.Close()

	// Wait for the socket to actually get free.
	if err := waitForClosedPortUDP(p, newPort); err != nil {
		t.Fatalf(err.Error())
	}
	if svcInfo.proxyPort == newPort {
		t.Errorf("expected difference, got %d %d", newPort, svcInfo.proxyPort)
	}
	p.OnUpdate([]api.Service{
		{ObjectMeta: api.ObjectMeta{Name: "echo"}, Spec: api.ServiceSpec{Port: newPort, Protocol: "UDP", ProxyPort: newPort}, Status: api.ServiceStatus{}},
	})
	if err := waitForClosedPortUDP(p, svcInfo.proxyPort); err != nil {
		t.Fatalf(err.Error())
	}
	testEchoUDP(t, "127.0.0.1", newPort)

	// Ensure the old port is released and re-usable.
	pc, err = net.ListenPacket("udp", joinHostPort("", svcInfo.proxyPort))
	if err != nil {
		t.Fatalf("can't claim released port: %s", err)
	}
	pc.Close()
}

// TODO: Test UDP timeouts.


text:
#include <libunwind.h>
#include <signal.h>
#include <stdio.h>

#include "backtrace_testlib.h"

void test_loop_forever() {
  while (1)
    ;
}

void test_signal_handler(int) { test_loop_forever(); }

void test_signal_action(int, siginfo_t*, void*) { test_loop_forever(); }

int test_level_four(int one, int two, int three, int four, void (*callback_func)(void*),
                    void* data) {
  if (callback_func != NULL) {
    callback_func(data);
  } else {
    while (1)
      ;
  }
  return one + two + three + four;
}

int test_level_three(int one, int two, int three, int four, void (*callback_func)(void*),
                     void* data) {
  return test_level_four(one + 3, two + 6, three + 9, four + 12, callback_func, data) + 3;
}

int test_level_two(int one, int two, int three, int four, void (*callback_func)(void*), void* data) {
  return test_level_three(one + 2, two + 4, three + 6, four + 8, callback_func, data) + 2;
}

int test_level_one(int one, int two, int three, int four, void (*callback_func)(void*), void* data) {
  return test_level_two(one + 1, two + 2, three + 3, four + 4, callback_func, data) + 1;
}

int test_recursive_call(int level, void (*callback_func)(void*), void* data) {
  if (level > 0) {
    return test_recursive_call(level - 1, callback_func, data) + level;
  } else if (callback_func != NULL) {
    callback_func(data);
  } else {
    while (1) {
    }
  }
  return 0;
}

typedef struct {
  unw_context_t* unw_context;
  volatile int* exit_flag;
} GetContextArg;

static void GetContextAndExit(void* data) {
  GetContextArg* arg = (GetContextArg*)data;
  unw_getcontext(arg->unw_context);
  // Don't touch the stack anymore.
  while (*arg->exit_flag == 0) {
  }
}

void test_get_context_and_wait(unw_context_t* unw_context, volatile int* exit_flag) {
  GetContextArg arg;
  arg.unw_context = unw_context;
  arg.exit_flag = exit_flag;
  test_level_one(1, 2, 3, 4, GetContextAndExit, &arg);
}


text:
#ifndef cmVariableWatchCommand_h
#define cmVariableWatchCommand_h

#include "cmCommand.h"

class cmVariableWatchCommandHandler
{
public:
  typedef std::vector<std::string> VectorOfCommands;
  VectorOfCommands Commands;
};

/** \class cmVariableWatchCommand
 * \brief Watch when the variable changes and invoke command
 *
 */
class cmVariableWatchCommand : public cmCommand
{
public:
  /**
   * This is a virtual constructor for the command.
   */
  virtual cmCommand* Clone()
    {
    return new cmVariableWatchCommand;
    }

  //! Default constructor
  cmVariableWatchCommand();

  /**
   * This is called when the command is first encountered in
   * the CMakeLists.txt file.
   */
  virtual bool InitialPass(std::vector<std::string> const& args,
                           cmExecutionStatus &status);

  /**
   * This determines if the command is invoked when in script mode.
   */
  virtual bool IsScriptable() { return true; }

  /**
   * The name of the command as specified in CMakeList.txt.
   */
  virtual const char* GetName() { return "variable_watch";}

  /**
   * Succinct documentation.
   */
  virtual const char* GetTerseDocumentation()
    {
    return "Watch the CMake variable for change.";
    }

  /**
   * More documentation.
   */
  virtual const char* GetFullDocumentation()
    {
    return
      "  variable_watch(<variable name> [<command to execute>])\n"
      "If the specified variable changes, the message will be printed about "
      "the variable being changed. If the command is specified, the command "
      "will be executed. The command will receive the following arguments:"
      " COMMAND(<variable> <access> <value> <current list file> <stack>)";
    }

  cmTypeMacro(cmVariableWatchCommand, cmCommand);

  void VariableAccessed(const std::string& variable, int access_type,
    const char* newValue, const cmMakefile* mf);

protected:
  std::map<std::string, cmVariableWatchCommandHandler> Handlers;

  bool InCallback;
};

#endif


text:
		<ui-gmap-google-map control="map.gmap" center="map.center" zoom="map.zoom" draggable="true" options="options" >
		<ui-gmap-markers control="map.markercontrol" models="wellMarkers" coords="'self'" icon="'icon'" click="'onClick'" idKey="'wellid'" events="map.markersEvents">
		</ui-gmap-markers>
		<ui-gmap-map-control template="control.tpl.html" index="-1" controller='witsml.dashboard.incidents.map.controller'></ui-gmap-map-control>
		</ui-gmap-google-map>


text:
namespace Poco {

template <typename ch, typename tr, typename ba = BufferAllocator<ch> >
class BasicBufferedStreamBuf: public std::basic_streambuf<ch, tr>
	/// This is an implementation of a buffered streambuf
	/// that greatly simplifies the implementation of
	/// custom streambufs of various kinds.
	/// Derived classes only have to override the methods
	/// readFromDevice() or writeToDevice().
	///
	/// This streambuf only supports unidirectional streams.
	/// In other words, the BasicBufferedStreamBuf can be
	/// used for the implementation of an istream or an
	/// ostream, but not for an iostream.
{
protected:
	typedef std::basic_streambuf<ch, tr> Base;
	typedef std::basic_ios<ch, tr> IOS;
	typedef ch char_type;
	typedef tr char_traits;
	typedef ba Allocator;
	typedef typename Base::int_type int_type;
	typedef typename Base::pos_type pos_type;
	typedef typename Base::off_type off_type;
	typedef typename IOS::openmode openmode;

public:
	BasicBufferedStreamBuf(std::streamsize bufferSize, openmode mode):
		_bufsize(bufferSize),
		_pBuffer(Allocator::allocate(_bufsize)),
		_mode(mode)
	{
		this->setg(_pBuffer + 4, _pBuffer + 4, _pBuffer + 4);
		this->setp(_pBuffer, _pBuffer + (_bufsize - 1));
	}

	~BasicBufferedStreamBuf()
	{
		Allocator::deallocate(_pBuffer, _bufsize);
	}

	virtual int_type overflow(int_type c)
	{
		if (!(_mode & IOS::out)) return char_traits::eof();

		if (c != char_traits::eof())
		{
			*this->pptr() = char_traits::to_char_type(c);
			this->pbump(1);
		}
		if (flushBuffer() == std::streamsize(-1)) return char_traits::eof();

		return c;
	}

	virtual int_type underflow()
	{
		if (!(_mode & IOS::in)) return char_traits::eof();

		if (this->gptr() && (this->gptr() < this->egptr()))
			return char_traits::to_int_type(*this->gptr());

		int putback = int(this->gptr() - this->eback());
		if (putback > 4) putback = 4;

		char_traits::move(_pBuffer + (4 - putback), this->gptr() - putback, putback);

		int n = readFromDevice(_pBuffer + 4, _bufsize - 4);
		if (n <= 0) return char_traits::eof();

		this->setg(_pBuffer + (4 - putback), _pBuffer + 4, _pBuffer + 4 + n);

		// return next character
		return char_traits::to_int_type(*this->gptr());
	}

	virtual int sync()
	{
		if (this->pptr() && this->pptr() > this->pbase())
		{
			if (flushBuffer() == -1) return -1;
		}
		return 0;
	}

protected:
	void setMode(openmode mode)
	{
		_mode = mode;
	}

	openmode getMode() const
	{
		return _mode;
	}

private:
	virtual int readFromDevice(char_type* buffer, std::streamsize length)
	{
		return 0;
	}

	virtual int writeToDevice(const char_type* buffer, std::streamsize length)
	{
		return 0;
	}

	int flushBuffer()
	{
		int n = int(this->pptr() - this->pbase());
		if (writeToDevice(this->pbase(), n) == n)
		{
			this->pbump(-n);
			return n;
		}
		return -1;
	}

	std::streamsize _bufsize;
	char_type*      _pBuffer;
	openmode        _mode;

	BasicBufferedStreamBuf(const BasicBufferedStreamBuf&);
	BasicBufferedStreamBuf& operator = (const BasicBufferedStreamBuf&);
};

//
// We provide an instantiation for char
//
typedef BasicBufferedStreamBuf<char, std::char_traits<char> > BufferedStreamBuf;

} // namespace Poco

#endif // Foundation_BufferedStreamBuf_INCLUDED


text:
@implementation CIAffineTransform

-(void)encodeWithCoder:(NSCoder *)coder {
   NSUnimplementedMethod();
}

-initWithCoder:(NSCoder *)coder {
   if([coder allowsKeyedCoding]){
    NSKeyedUnarchiver *keyed=(NSKeyedUnarchiver *)coder;

    _transform=[[keyed decodeObjectForKey:@"CI_inputTransform"] copy];
    _ciEnabled=[keyed decodeBoolForKey:@"CIEnabled"];
   }
   return self;
}

-(void)dealloc {
  [_transform release];
  [super dealloc];
}

-(NSAffineTransform *)affineTransform {
   return _transform;
}

@end


text:
using System;
using Cirrious.CrossCore.Droid;

namespace Iseteki.MvvmCross.Plugin.TextToSpeech.Droid
{
    public class DroidTextToSpeech : Java.Lang.Object, ITextToSpeech, Android.Speech.Tts.TextToSpeech.IOnInitListener
    {
        Android.Speech.Tts.TextToSpeech _tts;
        IMvxAndroidGlobals _globals;

        public DroidTextToSpeech(IMvxAndroidGlobals globals)
        {
            _globals = globals;
        }

        #region ITextToSpeech implementation

        public event EventHandler InitializeCompleted;

        public void Initialize()
        {
            if (_tts == null)
            {
                _tts = new Android.Speech.Tts.TextToSpeech(_globals.ApplicationContext, this);
            }
        }

        public void Release()
        {
            if (_tts != null)
            {
                _tts.Shutdown();
                _tts.Dispose();
                _tts = null;
                Initialized = false;
            }
        }

        public void Speech(string text)
        {
            if (Initialized == false)
            {
                throw new InvalidOperationException();
            }
            Java.Util.Locale locale = Java.Util.Locale.English;
            if (Locale == SpeechLocale.Japanease)
            {
                locale = Java.Util.Locale.Japanese;
            }
            switch (_tts.IsLanguageAvailable(locale))
            {
                case Android.Speech.Tts.LanguageAvailableResult.MissingData:
                case Android.Speech.Tts.LanguageAvailableResult.NotSupported:
                    throw new NotSupportedException();
                default:
                    _tts.SetLanguage(locale);
                    break;
            }
            _tts.Speak(text, Android.Speech.Tts.QueueMode.Flush, null);
        }

        public bool Initialized { get; private set; }

        public SpeechLocale Locale { get; set; }

        #endregion

        #region IOnInitListener implementation

        public void OnInit(Android.Speech.Tts.OperationResult status)
        {
            if (status == Android.Speech.Tts.OperationResult.Success)
            {
                Initialized = true;
                if (InitializeCompleted != null)
                {
                    InitializeCompleted(this, EventArgs.Empty);
                }
            }
        }

        #endregion
    }
}


text:
'use strict';

/**
 * Billing information related properties of a server.
 *
 */
class Sku {
  /**
   * Create a Sku.
   * @member {string} [name] The name of the sku, typically, tier + family +
   * cores, e.g. B_Gen4_1, GP_Gen5_8.
   * @member {string} [tier] The tier of the particular SKU, e.g. Basic.
   * Possible values include: 'Basic', 'GeneralPurpose', 'MemoryOptimized'
   * @member {number} [capacity] The scale up/out capacity, representing
   * server's compute units.
   * @member {string} [size] The size code, to be interpreted by resource as
   * appropriate.
   * @member {string} [family] The family of hardware.
   */
  constructor() {
  }

  /**
   * Defines the metadata of Sku
   *
   * @returns {object} metadata of Sku
   *
   */
  mapper() {
    return {
      required: false,
      serializedName: 'Sku',
      type: {
        name: 'Composite',
        className: 'Sku',
        modelProperties: {
          name: {
            required: false,
            serializedName: 'name',
            type: {
              name: 'String'
            }
          },
          tier: {
            required: false,
            serializedName: 'tier',
            type: {
              name: 'String'
            }
          },
          capacity: {
            required: false,
            serializedName: 'capacity',
            constraints: {
              InclusiveMinimum: 0
            },
            type: {
              name: 'Number'
            }
          },
          size: {
            required: false,
            serializedName: 'size',
            type: {
              name: 'String'
            }
          },
          family: {
            required: false,
            serializedName: 'family',
            type: {
              name: 'String'
            }
          }
        }
      }
    };
  }
}

module.exports = Sku;


text: Alternate storage for Cities:Skylines Props.


text:
package com.rayram23.webcrawler.parser;

import static org.junit.Assert.*;

import java.net.URI;
import java.net.URISyntaxException;

import org.junit.Test;

public class UriParserTest {

	@Test
	public void testExtractDomainSimple() throws URISyntaxException{
		URI testUri = new URI("http://rayram.com");
		UriParser testClass = new UriParser();
		assertEquals("rayram.com",testClass.extractDomain(testUri));
	}
	@Test
	public void testExtractDomainWithSubDomain() throws URISyntaxException{
		URI testUri = new URI("http://subdomain.rayram.com");
		UriParser testClass = new UriParser();
		assertEquals("subdomain.rayram.com",testClass.extractDomain(testUri));
	}
	@Test
	public void testExtractDomainWithSubPage() throws URISyntaxException{
		URI testUri = new URI("http://rayram.com/page.html");
		UriParser testClass = new UriParser();
		assertEquals("rayram.com",testClass.extractDomain(testUri));
	}
	@Test
	public void testIsUrlOnDomainTrue() throws URISyntaxException{
		URI testUri = new URI("http://rayram.com/page.html");
		UriParser testClass = new UriParser();
		assertTrue("rayram.com",testClass.isUrlOnDomain(testUri, new URI("http://rayram.com")));
	}
	@Test
	public void testIsUrlOnDomainFalse() throws URISyntaxException{
		URI testUri = new URI("http://rayram.googlr.com/page.html");
		UriParser testClass = new UriParser();
		assertFalse("rayram.com",testClass.isUrlOnDomain(testUri, new URI("http://rayram.com")));
	}
	@Test
	public void testUrl() throws URISyntaxException{
		URI testUri = new URI("https://www.yahoo.com/movies/hunger-games-mockingjay-part-2-trailer-the-121111532492.html");
		UriParser testClass = new UriParser();
		assertTrue(testClass.isUrlOnDomain(testUri, new URI("http://www.yahoo.com")));
	}
}


text:
A node module for drawing boxes around a DOM selection.

## Install

```
npm install draw-selection
```

## Run

`drawSelection([containerEl [, styles]])`

### args
* `containerEl` - (optional) `Element` to insert the boxes (assumes the selection is relative to that container)
* `styles` - (optional) `object` that contains CSS properties and values to apply to the boxes (default `{ outline: '1px solid red', 'pointer-events': 'none' }`)

### returns
* `els` - an array of `Element`s that were created

```html
<html>
<body>
<p>hello, world!</p>
</body>
</html>
```

```js

var drawSelection = require('draw-selection')
var sel = window.getSelection()
sel.removeAllRanges()

var range = document.createRange()
range.selectNode(document.querySelector('p'))
sel.addRange(range)

drawSelection({
  outline: '1px inset blue'
})
```

## License

([The MIT License](LICENSE))

Copyright 2015 Cameron Lakenen