Esempio n. 1
0
def raw_group_num_questions(divisors,messages,qh,rh,wh):
	'''
	purpose, preconditions, comments
		same as for group_count except that the number of questions
		generated by the return value of raw_group is returned
	'''
	d_len = len(divisors[0])
	m_len = len(messages[0])

	q_len = crc_util.quotient_len(d_len,m_len)
	r_len = crc_util.remainder_len(d_len,m_len)
	num_rows = crc_util.number_of_rows(d_len,m_len)
	row_width = crc_util.row_width(d_len,m_len)

	q_indexes = range(0,q_len)
	r_indexes = range(0,r_len)
	w_indexes = generate_util.cross_product \
		([range(num_rows),range(row_width)])

	return len(divisors) * len(messages) * \
		generate_util.n_c_k(q_len,qh) * \
		generate_util.n_c_k(r_len,rh) * \
		generate_util.n_c_k(num_rows*row_width,wh)
source_language = 'C'

hotspot_declarations = [
	['$a0','int'],['$r','int'],
	['$y0','int'],['$y1','int'],['$y2','int'],['$y3','int'],['$y4','int'],
]

group_templates = [
	 [ 'arithmetic_progression_a_h%i_', [0,1, 0,1,2,3,4] ],
	 [ 'arithmetic_progression_b_h%i_', [0,5, 0,5,10,15,20] ],
	 [ 'arithmetic_progression_c_h%i_', [7,3, 7,10,13,16,19] ],
]

print '***** expected number of questions:', \
 len(group_templates) * (generate_util.n_c_k(7,1) + generate_util.n_c_k(7,2))

group_list = [ ]
for g in group_templates:
	for h in [1,2]:
		group_list.append([g[0]%h] + generate_util.generalize(g[1],h))

global_code_template = '''\
d	#include <stdio.h>
x	#include <stdio.h>
dx
'''

main_code_template = '''\
dx		int a,r,i;
dx
import generate_util

# counting -------------------------------------------------------
cut = 'n_c_k'
actual = generate_util.n_c_k(3,2)
expected = 3
message = '''Error in %s:
\tactual: %s
\texpect: %s
if actual != expected:
	print message % (cut,str(actual),str(expected))
'''

# Group_list -------------------------------------------------------

# ********** cross_product
G = generate_util.Group_list([ ['g', [[0,1], 'x', [2,3]]] ],3)
G.cross_product(None,[0,2])
actual = G.group_list
expected = [       
	['g', [0, 'x', 2], [0, 'x', 3], [1, 'x', 2], [1, 'x', 3]],
]
message = '''Error in %s:
\tactual: %s
\texpected: %s
'''
if actual != expected:
	print message % (cut,str(actual),str(expected))

cut = 'cross_product'
G = generate_util.Group_list([ ['g', [[0,1], 'x', [2,3]]] ],3)
    ['$r', 'int'],
    ['$y0', 'int'],
    ['$y1', 'int'],
    ['$y2', 'int'],
    ['$y3', 'int'],
    ['$y4', 'int'],
]

group_templates = [
    ['arithmetic_progression_a_h%i_', [0, 1, 0, 1, 2, 3, 4]],
    ['arithmetic_progression_b_h%i_', [0, 5, 0, 5, 10, 15, 20]],
    ['arithmetic_progression_c_h%i_', [7, 3, 7, 10, 13, 16, 19]],
]

print '***** expected number of questions:', \
 len(group_templates) * (generate_util.n_c_k(7,1) + generate_util.n_c_k(7,2))

group_list = []
for g in group_templates:
    for h in [1, 2]:
        group_list.append([g[0] % h] + generate_util.generalize(g[1], h))

global_code_template = '''\
d	#include &lt;stdio.h>
x	#include <stdio.h>
dx
'''

main_code_template = '''\
dx		int a,r,i;
dx
for g in raw_group_list0:
	g[0] = g[0] % 2
G2 = generate_util.Group_list(raw_group_list0,4)
G2.generalize(None,hotspot_indexes,2)

raw_group_list0 = copy.deepcopy(raw_group_list)
for g in raw_group_list0:
	g[0] = g[0] % 3
G3 = generate_util.Group_list(raw_group_list0,4)
G3.generalize(None,hotspot_indexes,3)

# concatenate for solution
group_list = G1.group_list + G2.group_list + G3.group_list

print '***** expected number of questions:', len(raw_group_list) * \
(generate_util.n_c_k(3,1) + generate_util.n_c_k(3,2) + generate_util.n_c_k(3,3))
#	= 10 * (3 + 3 + 1) = 70

global_code_template = '''\
d	#include &lt;stdio.h>
x	#include <stdio.h>
dx
'''

main_code_template = '''\
dx		int r,i;
dx		double x;
dx
dx		r = $r;
dx		x = 1.0;
dx		for (i = 0; i < 3; i++) {
for g in raw_group_list0:
    g[0] = g[0] % 2
G2 = generate_util.Group_list(raw_group_list0, 4)
G2.generalize(None, hotspot_indexes, 2)

raw_group_list0 = copy.deepcopy(raw_group_list)
for g in raw_group_list0:
    g[0] = g[0] % 3
G3 = generate_util.Group_list(raw_group_list0, 4)
G3.generalize(None, hotspot_indexes, 3)

# concatenate for solution
group_list = G1.group_list + G2.group_list + G3.group_list

print '***** expected number of questions:', len(raw_group_list) * \
(generate_util.n_c_k(3,1) + generate_util.n_c_k(3,2) + generate_util.n_c_k(3,3))
#	= 10 * (3 + 3 + 1) = 70

global_code_template = '''\
d	#include &lt;stdio.h>
x	#include <stdio.h>
dx
'''

main_code_template = '''\
dx		int r,i;
dx		double x;
dx
dx		r = $r;
dx		x = 1.0;
dx		for (i = 0; i < 3; i++) {
Esempio n. 7
0
import generate_util

# counting -------------------------------------------------------
cut = 'n_c_k'
actual = generate_util.n_c_k(3, 2)
expected = 3
message = '''Error in %s:
\tactual: %s
\texpect: %s
if actual != expected:
	print message % (cut,str(actual),str(expected))
'''

# Group_list -------------------------------------------------------

# ********** cross_product
G = generate_util.Group_list([['g', [[0, 1], 'x', [2, 3]]]], 3)
G.cross_product(None, [0, 2])
actual = G.group_list
expected = [
    ['g', [0, 'x', 2], [0, 'x', 3], [1, 'x', 2], [1, 'x', 3]],
]
message = '''Error in %s:
\tactual: %s
\texpected: %s
'''
if actual != expected:
    print message % (cut, str(actual), str(expected))

cut = 'cross_product'
G = generate_util.Group_list([['g', [[0, 1], 'x', [2, 3]]]], 3)