progs/cpp/teststrings.cpp
author Christian Urban <christian.urban@kcl.ac.uk>
Wed, 09 Feb 2022 00:29:04 +0000
changeset 424 2416fdec6396
parent 163 4ffa09e33773
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
163
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
//============================================================================
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
// Name        : teststrings.cpp
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
// Author      : Lasse Nielson
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
//
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
// Description : Generation of Test Strings for Regular Expressions
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
//
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
// Compile     : g++ -o teststrings teststrings.cpp
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
//============================================================================
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
#include <iostream>
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
#include <string>
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
#include <sstream>
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
using namespace std;
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
string str_email(int n) {
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
	stringstream ss;
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
	for (int i = 0; i < n; ++i) {
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
		for (int j = 0; j < i % 27 + 3; ++j)
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
			ss << (char) ('a' + (j % 26));
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
		if (n > i + 1)
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
			ss << "-";
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
	}
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
	ss << "@";
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
	for (int j = 0; j < 2; ++j) {
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
		for (int i = 0; i < n + 3; ++i)
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
			ss << (char) ('a' + ((i + j) % 26));
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
		ss << ".";
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
	}
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
	ss << "com";
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
	return ss.str();
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
}
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
string str_amount(int n) {
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
	stringstream ss;
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
	ss << "$";
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
	for (int i = 0; i < n; ++i) {
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
		ss << (1 + i) % 10;
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
		if (n > i + 1 && (n - i) % 3 == 1)
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
			ss << ",";
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
	}
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
	ss << ".53";
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
	return ss.str();
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
}
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
string str_float(int n) {
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
	stringstream ss;
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
	ss << "-";
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
	for (int i = 0; i < n; ++i) {
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
		ss << (1 + i) % 10;
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
	}
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
	ss << ".";
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
	for (int i = 0; i < n; ++i) {
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
		ss << (1 + i) % 10;
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
	}
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
	ss << "E+";
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
	for (int i = 0; i < n; ++i) {
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
		ss << (1 + i) % 10;
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
	}
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
	return ss.str();
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
}
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
int main() {
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
    
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
        int fin = 10;
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
	// emails 
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
        for (int i = 1; i < fin; i++) {
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
          cout << str_email(i) << endl;
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
        }
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
        // dollar amounts
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
        for (int i = 1; i < fin; i++) {
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
	  cout << str_amount(i) << endl;
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
        }
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
        // float numbers
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
        for (int i = 1; i < fin; i++) {
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
	  cout << str_float(i) << endl;
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
        }
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
	return 0;
4ffa09e33773 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
}