Ejemplo n.º 1
0
void do_test_clipOutOfRangeInZ()
{
	MAP  pts0;
	load_demo_9pts_map(pts0);

	// Clip: z=[-10,-1] -> 0 pts
	{
		MAP  pts = pts0;
		pts.clipOutOfRangeInZ(-10,-1);
		EXPECT_EQ(pts.size(),0u);
	}

	// Clip: z=[-10,10] -> 9 pts
	{
		MAP  pts = pts0;
		pts.clipOutOfRangeInZ(-10,10);
		EXPECT_EQ(pts.size(),9u);
	}

	// Clip: z=[0.5,1.5] -> 3 pts
	{
		MAP  pts = pts0;
		pts.clipOutOfRangeInZ(0.5,1.5);
		EXPECT_EQ(pts.size(),3u);
	}

}
Ejemplo n.º 2
0
    void
    verify_MultimapIters()  ///< @see IterTools_test#verify_filterRepetitions
    {
        MAP testMap;
        for (uint i=0; i<NUM_ELMS; ++i)
        {
            uint n = 1 + rand() % 100;
            do testMap.insert (make_pair (i,n));
            while (--n);
        }
        CHECK (NUM_ELMS < testMap.size(), "no repetition in test data??");

        IntIter keys = eachDistinctKey (testMap);

        cout << "distinct_keys";
        CHECK (keys);
        pullOut (keys);
        CHECK (!keys);

        cout << "values_4_key";
        IntIter vals = eachValForKey (testMap, NUM_ELMS); // non-existent key
        CHECK (!vals);

        vals = eachValForKey (testMap, 0);
        CHECK (vals);
        pullOut (vals); // should produce anything between 1 and 100 entries
        CHECK (!vals);
    }
Ejemplo n.º 3
0
void do_test_clipOutOfRange()
{
	MAP  pts0;
	load_demo_9pts_map(pts0);

	// Clip:
	{
		CPoint2D pivot(0,0);
		const float radius = 0.5;

		MAP  pts = pts0;
		pts.clipOutOfRange(pivot,radius);
		EXPECT_EQ(pts.size(),1u);
	}

	// Clip:
	{
		CPoint2D pivot(-10,-10);
		const float radius = 1;

		MAP  pts = pts0;
		pts.clipOutOfRange(pivot,radius);
		EXPECT_EQ(pts.size(),0u);
	}

	// Clip:
	{
		CPoint2D pivot(0,0);
		const float radius = 1.1;

		MAP  pts = pts0;
		pts.clipOutOfRange(pivot,radius);
		EXPECT_EQ(pts.size(),3u);
	}

}
void map_histogram(std::ostream &out, const MAP &map) {
  std::vector<int> hist;
  for (typename MAP::const_iterator i = map.begin(); i != map.end(); ++i) {
    size_t n = (*i).second.size();
    if (hist.size() <= n) {
      hist.resize(n + 1);
    }
    hist[n]++;
  }
  int total = map.size();
  std::string bar(50, '*');
  for (size_t i = 0; i < hist.size(); i++) {
    if (hist[i] > 0) {
      out << std::setw(5) << i << " : " << std::setw(5) << hist[i] << " " << bar.substr(50 - hist[i] * 50 / total) << std::endl;
    }
  }
}
Ejemplo n.º 5
0
void do_test_insertPoints()
{
	// test 1: Insert and check expected values:
	{
		MAP  pts;
		load_demo_9pts_map(pts);

		EXPECT_EQ(pts.size(),demo9_N);

		for (size_t i=0;i<demo9_N;i++)
		{
			float x,y,z;
			pts.getPoint(i,x,y,z);
			EXPECT_EQ(x,demo9_xs[i]);
			EXPECT_EQ(y,demo9_ys[i]);
			EXPECT_EQ(z,demo9_zs[i]);
		}
	}

	// test 2: Copy between maps
	{
		MAP  pts1;
		load_demo_9pts_map(pts1);

		MAP  pts2 = pts1;
		MAP  pts3 = pts1;

		EXPECT_EQ(pts2.size(),pts3.size());
		for (size_t i=0;i<demo9_N;i++)
		{
			float x2,y2,z2;
			float x3,y3,z3;
			pts2.getPoint(i,x2,y2,z2);
			pts3.getPoint(i,x3,y3,z3);
			EXPECT_EQ(x2,x3);
			EXPECT_EQ(y2,y3);
			EXPECT_EQ(z2,z3);
		}
	}

}
Ejemplo n.º 6
0
int main()
{
    MAP table;

    string name;

    /******************************************************
* PHASE 0: Load the words in the text file *
* into a the table *
*******************************************************/

    cout << "File name? ";
    getline(cin, name);

    ifstream textFile(name.c_str());

    if (!textFile)
    {
        cerr << "Text file could not be opened!!" << endl;
        return 0;
    }

    string word;
    int nWords = 0;

    while(textFile >> word)
    {
        nWords++;
        //remove non-alpha chars
        word.erase(remove_if(word.begin(), word.end(), isNotAlpha), word.end());
        //convert to lower-case letters
        transform(word.begin(), word.end(), word.begin(), ::tolower);
        if (word == "") continue;

        ELEMENT e = make_pair(word,1);
        cout << word << endl;
        table.BST_threaded::insert(e);
    }

    textFile.close();

    /******************************************************
* PHASE 1: Display *
* - number of words in the text *
* - number of unique words (occurring only once) *
* - frequency table *
*******************************************************/
    //number of words in the text
    cout << "The number of words in the text file is: " << nWords << endl;
    cout << "Number of unique words in the file: " << table.size() << endl;

    cout << "\n\nTable sorted alphabetically:"
         << endl << endl;

    BiIterator it = table.begin();

    cout << " \tKEY" << "\tCOUNTER" << endl;
    cout << "==============================\n";
    for( ; it != table.end(); it++)
    {
         cout << setw(15) << it->first
              << setw(15) << it->second << endl;
    }


    /******************************************************
* PHASE 3: remove all words with counter 1 *
* and display table again *
*******************************************************/

    it = table.begin();
    vector<string> temp;
    for( ; it != table.end(); it++){
        if(it->second == 1){
            temp.push_back(it->first);
        }
    }
    for(int i = 0; i != temp.size(); i ++){
        table.remove(temp[i]);
    }


    cout << "Number of words after remove: " << table.size() << endl;

    cout << "Un-unique table sorted alphabetically:" << endl;

    cout << " \tKEY" << "\tCOUNTER" << endl;
    cout << "==============================\n";
    for(it = table.begin(); it != table.end(); it++) {
         cout << setw(15) << it->first
              << setw(15) << it->second << endl;
    }


    /***********************************************************
* PHASE 4: request two words to the user w1 and w2 *
* then display all words in the interval [w1,w2] *
************************************************************/
    //We assume that the words entered by the user exists in the table
    cout << "Please enter two words from the list " << endl;
    string first, last;
    cin >> first >> last;
    cout << "First: " << first << " and last: " << last << endl;
    BiIterator itr = table.find(first);
    BiIterator stop = table.find(last);
    itr--; //a dummy to include the last node
    for(stop; stop!=itr; stop--){
        cout << setw(15) << stop->first
        << setw(15) << stop->second << endl;
    }
    return 0;
}
Ejemplo n.º 7
0
 size_t nterms() const { return terms.size(); }
Ejemplo n.º 8
0
		static size_t			Size( void ){
			return m_Sessions.size();
		}