Erlang : Test Module 3


-module(test_b).
-export([test/2]).
	
insert(N, BeginFrom) ->
	case N of
		0 ->
			done;
		Else ->
			insert_many(N, BeginFrom)
	end.

tsact(N, CS, BeginFrom) ->
	case N of
		0 ->
			done;
		Else ->
			io:fwrite("begin N = ~p~n", [N]),
			LastNum = insert(CS, BeginFrom),
			io:fwrite("end~n"),
			tsact(N-1, CS, LastNum)
	end.

test(NumRecords, ChunkSize) ->
	TSacts = NumRecords / ChunkSize,
	%io:fwrite("TSacts ~p~n", [round(TSacts)]).
	tsact(round(TSacts), ChunkSize, 999).

	
%==============================================

insert_many(0, Number) ->
	Number;
insert_many(N, Number) ->
	Record = [{dst, Number},{msg, <<"test msg">>}],
	io:fwrite("~p~n", [Record]),
	%sqlite3:write(?DB_NAME, ?TBL_NAME, Record),
	insert_many(N-1, Number+1).
	

Sample Output


3> test_b:test(12, 2).
begin N = 6
[{dst,94770000000},{msg,<<"test msg">>}]
[{dst,94770000001},{msg,<<"test msg">>}]
end
begin N = 5
[{dst,94770000002},{msg,<<"test msg">>}]
[{dst,94770000003},{msg,<<"test msg">>}]
end
begin N = 4
[{dst,94770000004},{msg,<<"test msg">>}]
[{dst,94770000005},{msg,<<"test msg">>}]
end
begin N = 3
[{dst,94770000006},{msg,<<"test msg">>}]
[{dst,94770000007},{msg,<<"test msg">>}]
end
begin N = 2
[{dst,94770000008},{msg,<<"test msg">>}]
[{dst,94770000009},{msg,<<"test msg">>}]
end
begin N = 1
[{dst,94770000010},{msg,<<"test msg">>}]
[{dst,94770000011},{msg,<<"test msg">>}]
end
done
4> 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: