-
-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #327 from kaushik94/testing-getters-setters
[GSoC 2015 MRG] Testing getters setters
- Loading branch information
Showing
2 changed files
with
339 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
||
#include "rpacket.h" | ||
#include "status.h" | ||
|
||
bool test_rpacket_get_nu(double); | ||
bool test_rpacket_get_mu(double); | ||
bool test_rpacket_get_energy(double); | ||
bool test_rpacket_get_r(double); | ||
bool test_rpacket_get_tau_event(double); | ||
bool test_rpacket_get_nu_line(double); | ||
bool test_rpacket_get_d_boundary(double); | ||
bool test_rpacket_get_d_electron(double); | ||
bool test_rpacket_get_d_line(double); | ||
|
||
|
||
bool test_rpacket_get_current_shell_id(unsigned int); | ||
bool test_rpacket_get_next_line_id(unsigned int); | ||
|
||
bool test_rpacket_get_recently_crossed_boundary(int); | ||
bool test_rpacket_get_virtual_packet_flag(int); | ||
bool test_rpacket_get_virtual_packet(int); | ||
bool test_rpacket_get_next_shell_id(int); | ||
|
||
bool test_rpacket_get_last_line(void); | ||
bool test_rpacket_get_close_line(void); | ||
bool test_rpacket_get_status(void); | ||
|
||
bool | ||
test_rpacket_get_nu(double value){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_nu(rp, value); | ||
if( value != rpacket_get_nu(rp) ){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool | ||
test_rpacket_get_mu(double value){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_mu(rp, value); | ||
if( value != rpacket_get_mu(rp) ){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool | ||
test_rpacket_get_energy(double value){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_energy(rp, value); | ||
if( value != rpacket_get_energy(rp) ){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool | ||
test_rpacket_get_r(double value){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_r(rp, value); | ||
if( value != rpacket_get_r(rp) ){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool | ||
test_rpacket_get_tau_event(double value){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_tau_event(rp, value); | ||
if( value != rpacket_get_tau_event(rp) ){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool | ||
test_rpacket_get_nu_line(double value){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_nu_line(rp, value); | ||
if( value != rpacket_get_nu_line(rp) ){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool | ||
test_rpacket_get_current_shell_id(unsigned int value){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_nu_line(rp, value); | ||
if( value != rpacket_get_nu_line(rp) ){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool | ||
test_rpacket_get_next_line_id(unsigned int value){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_next_line_id(rp, value); | ||
if( value != rpacket_get_next_line_id(rp) ){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool | ||
test_rpacket_get_last_line(void){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_last_line(rp, true); | ||
return rpacket_get_last_line(rp); | ||
} | ||
|
||
bool | ||
test_rpacket_get_close_line(void){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_last_line(rp, true); | ||
return rpacket_get_last_line(rp); | ||
} | ||
|
||
bool | ||
test_rpacket_get_recently_crossed_boundary(int value){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_recently_crossed_boundary(rp, value); | ||
if( value != rpacket_get_recently_crossed_boundary(rp) ){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool | ||
test_rpacket_get_virtual_packet_flag(int value){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_virtual_packet_flag(rp, value); | ||
if( value != rpacket_get_virtual_packet_flag(rp) ){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool | ||
test_rpacket_get_virtual_packet(int value){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_virtual_packet(rp, value); | ||
if( value != rpacket_get_virtual_packet(rp) ){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool | ||
test_rpacket_get_d_boundary(double value){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_d_boundary(rp, value); | ||
if( value != rpacket_get_d_boundary(rp) ){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool | ||
test_rpacket_get_d_electron(double value){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_d_electron(rp, value); | ||
if( value != rpacket_get_d_electron(rp) ){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool | ||
test_rpacket_get_d_line(double value){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_d_line(rp, value); | ||
if( value != rpacket_get_d_line(rp) ){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool | ||
test_rpacket_get_next_shell_id(int value){ | ||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_next_shell_id(rp, value); | ||
if( value != rpacket_get_next_shell_id(rp) ){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool | ||
test_rpacket_get_status(void){ | ||
rpacket_status_t inProcess = TARDIS_PACKET_STATUS_IN_PROCESS; | ||
rpacket_status_t emitted = TARDIS_PACKET_STATUS_EMITTED; | ||
rpacket_status_t reabsorbed = TARDIS_PACKET_STATUS_REABSORBED; | ||
|
||
rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); | ||
rpacket_set_status(rp, inProcess); | ||
if( inProcess != rpacket_get_status(rp) ){ | ||
return false; | ||
} | ||
rpacket_set_status(rp, emitted); | ||
if( emitted != rpacket_get_status(rp) ){ | ||
return false; | ||
} | ||
rpacket_set_status(rp, reabsorbed); | ||
if( reabsorbed != rpacket_get_status(rp) ){ | ||
return false; | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import os | ||
import random | ||
from ctypes import CDLL, c_double | ||
|
||
import pytest | ||
import numpy as np | ||
|
||
from tardis import __path__ as path | ||
|
||
test_path = os.path.join(path[0], 'montecarlo', 'montecarlo.so') | ||
|
||
tests = CDLL(test_path) | ||
|
||
np.random.seed(1) | ||
|
||
|
||
def get_doubles(size=10): | ||
from sys import float_info as floats | ||
MAX_FLOAT, MIN_FLOAT = floats[0], floats[3] | ||
return map(c_double, np.random.uniform( | ||
MIN_FLOAT, MAX_FLOAT, size=10)) | ||
|
||
@pytest.fixture(params=get_doubles()) | ||
def double_value(request): | ||
return request.param | ||
|
||
|
||
def get_integers(size=10): | ||
MAX_INT, MIN_INT = 10000, -10000 | ||
return np.random.randint( | ||
MIN_INT, MAX_INT, size=10) | ||
|
||
@pytest.fixture(params=get_integers()) | ||
def int_value(request): | ||
return request.param | ||
|
||
|
||
def get_unsigned_integers(size=10): | ||
MAX_INT = 10000 | ||
return np.random.randint( | ||
0, MAX_INT, size=10) | ||
|
||
@pytest.fixture(params=get_unsigned_integers()) | ||
def unsigned_int_value(request): | ||
return request.param | ||
|
||
|
||
# Testing functions with float(C double) valued parameters | ||
|
||
def test_rpacket_get_nu(double_value): | ||
assert tests.test_rpacket_get_nu(double_value) | ||
|
||
|
||
def test_rpacket_get_mu(double_value): | ||
assert tests.test_rpacket_get_mu(double_value) | ||
|
||
|
||
def test_rpacket_get_energy(double_value): | ||
assert tests.test_rpacket_get_energy(double_value) | ||
|
||
|
||
def test_rpacket_get_r(double_value): | ||
assert tests.test_rpacket_get_r(double_value) | ||
|
||
|
||
def test_rpacket_get_tau_event(double_value): | ||
assert tests.test_rpacket_get_tau_event(double_value) | ||
|
||
|
||
def test_rpacket_get_nu_line(double_value): | ||
assert tests.test_rpacket_get_nu_line(double_value) | ||
|
||
|
||
def test_rpacket_get_d_boundary(double_value): | ||
assert tests.test_rpacket_get_d_boundary(double_value) | ||
|
||
|
||
def test_rpacket_get_d_electron(double_value): | ||
assert tests.test_rpacket_get_d_electron(double_value) | ||
|
||
|
||
def test_rpacket_get_d_line(double_value): | ||
assert tests.test_rpacket_get_d_line(double_value) | ||
|
||
|
||
# Testing functions with Unsigned Integer valued parameters | ||
|
||
def test_rpacket_get_current_shell_id(unsigned_int_value): | ||
assert tests.test_rpacket_get_current_shell_id(unsigned_int_value) | ||
|
||
|
||
def test_rpacket_get_next_line_id(unsigned_int_value): | ||
assert tests.test_rpacket_get_next_line_id(unsigned_int_value) | ||
|
||
|
||
# Testing functions with Integer valued parameters | ||
|
||
def test_rpacket_get_recently_crossed_boundary(int_value): | ||
assert tests.test_rpacket_get_recently_crossed_boundary(int_value) | ||
|
||
|
||
def test_rpacket_get_virtual_packet_flag(int_value): | ||
assert tests.test_rpacket_get_virtual_packet_flag(int_value) | ||
|
||
|
||
def test_rpacket_get_virtual_packet(int_value): | ||
assert tests.test_rpacket_get_virtual_packet(int_value) | ||
|
||
|
||
def test_rpacket_get_next_shell_id(int_value): | ||
assert tests.test_rpacket_get_next_shell_id(int_value) | ||
|
||
|
||
# Testing functions without any parameters | ||
def test_rpacket_get_last_line(): | ||
assert tests.test_rpacket_get_last_line() | ||
|
||
def test_rpacket_get_close_line(): | ||
assert tests.test_rpacket_get_close_line() | ||
|
||
def test_rpacket_get_status(): | ||
assert tests.test_rpacket_get_status() |