add copyright headers
This commit is contained in:
		
							parent
							
								
									62eca29932
								
							
						
					
					
						commit
						6163518c4c
					
				
							
								
								
									
										19
									
								
								lib/dice.c
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								lib/dice.c
									
									
									
									
									
								
							| @ -1,3 +1,22 @@ | ||||
| /*
 | ||||
|  * This file is part of libdice. | ||||
|  * | ||||
|  * Copyright (C) 2018 Florian Stinglmayr <florian@n0la.org> | ||||
|  * | ||||
|  * libdice is free software: you can redistribute it and/or modify it | ||||
|  * under the terms of the GNU Lesser General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  * | ||||
|  * libdice is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with libdice.  If not, see <http://www.gnu.org/licenses/>.
 | ||||
|  */ | ||||
| 
 | ||||
| #include "dice.h" | ||||
| #include "dice_parse.h" | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										19
									
								
								lib/dice.h
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								lib/dice.h
									
									
									
									
									
								
							| @ -1,3 +1,22 @@ | ||||
| /*
 | ||||
|  * This file is part of libdice. | ||||
|  * | ||||
|  * Copyright (C) 2018 Florian Stinglmayr <florian@n0la.org> | ||||
|  * | ||||
|  * libdice is free software: you can redistribute it and/or modify it | ||||
|  * under the terms of the GNU Lesser General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  * | ||||
|  * libdice is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with libdice.  If not, see <http://www.gnu.org/licenses/>.
 | ||||
|  */ | ||||
| 
 | ||||
| #ifndef LIBDICE_DICE_H | ||||
| #define LIBDICE_DICE_H | ||||
| 
 | ||||
|  | ||||
| @ -705,11 +705,13 @@ static void pn (const te_expr *n, int depth) { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| static void te_print(const te_expr *n) { | ||||
|     pn(n, 0); | ||||
| } | ||||
| 
 | ||||
| /* libdice specific functions
 | ||||
|  */ | ||||
| 
 | ||||
| struct dice_expression_ | ||||
| { | ||||
|     te_expr *expr; | ||||
|  | ||||
| @ -1,3 +1,22 @@ | ||||
| /*
 | ||||
|  * This file is part of libdice. | ||||
|  * | ||||
|  * Copyright (C) 2018 Florian Stinglmayr <florian@n0la.org> | ||||
|  * | ||||
|  * libdice is free software: you can redistribute it and/or modify it | ||||
|  * under the terms of the GNU Lesser General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  * | ||||
|  * libdice is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with libdice.  If not, see <http://www.gnu.org/licenses/>.
 | ||||
|  */ | ||||
| 
 | ||||
| #include <dice.h> | ||||
| 
 | ||||
| #include <setjmp.h> | ||||
|  | ||||
| @ -1,3 +1,22 @@ | ||||
| /*
 | ||||
|  * This file is part of libdice. | ||||
|  * | ||||
|  * Copyright (C) 2018 Florian Stinglmayr <florian@n0la.org> | ||||
|  * | ||||
|  * libdice is free software: you can redistribute it and/or modify it | ||||
|  * under the terms of the GNU Lesser General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  * | ||||
|  * libdice is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with libdice.  If not, see <http://www.gnu.org/licenses/>.
 | ||||
|  */ | ||||
| 
 | ||||
| #include <dice.h> | ||||
| 
 | ||||
| #include <setjmp.h> | ||||
|  | ||||
| @ -1,3 +1,22 @@ | ||||
| /*
 | ||||
|  * This file is part of libdice. | ||||
|  * | ||||
|  * Copyright (C) 2018 Florian Stinglmayr <florian@n0la.org> | ||||
|  * | ||||
|  * libdice is free software: you can redistribute it and/or modify it | ||||
|  * under the terms of the GNU Lesser General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  * | ||||
|  * libdice is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with libdice.  If not, see <http://www.gnu.org/licenses/>.
 | ||||
|  */ | ||||
| 
 | ||||
| #include <dice.h> | ||||
| 
 | ||||
| #include <setjmp.h> | ||||
|  | ||||
							
								
								
									
										107
									
								
								tests/test_expr_parse.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										107
									
								
								tests/test_expr_parse.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,107 @@ | ||||
| /*
 | ||||
|  * This file is part of libdice. | ||||
|  * | ||||
|  * Copyright (C) 2018 Florian Stinglmayr <florian@n0la.org> | ||||
|  * | ||||
|  * libdice is free software: you can redistribute it and/or modify it | ||||
|  * under the terms of the GNU Lesser General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  * | ||||
|  * libdice is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with libdice.  If not, see <http://www.gnu.org/licenses/>.
 | ||||
|  */ | ||||
| 
 | ||||
| #include <dice.h> | ||||
| 
 | ||||
| #include <setjmp.h> | ||||
| #include <cmocka.h> | ||||
| #include <stdio.h> | ||||
| #include <string.h> | ||||
| #include <stdlib.h> | ||||
| 
 | ||||
| static void test_expr_parse_none(void **arg) | ||||
| { | ||||
|     dice_expression_t e = NULL; | ||||
|     int error = 0; | ||||
| 
 | ||||
|     e = dice_expression_parse("", &error); | ||||
| 
 | ||||
|     assert_null(e); | ||||
|     assert_int_equal(error, 1); | ||||
| } | ||||
| 
 | ||||
| static void test_expr_parse_simple(void **arg) | ||||
| { | ||||
|     dice_expression_t e = NULL; | ||||
|     int error = 0, i = 0; | ||||
|     int64_t result = 0; | ||||
| 
 | ||||
|     e = dice_expression_parse("4d6", &error); | ||||
| 
 | ||||
|     assert_non_null(e); | ||||
|     assert_int_equal(error, 0); | ||||
| 
 | ||||
|     for (i = 0; i < 100000; i++) { | ||||
|         assert_true(dice_expression_evaluate(e, &result)); | ||||
|         assert_true(result >= 4 && result <= 32); | ||||
|     } | ||||
| 
 | ||||
|     dice_expression_free(e); | ||||
| } | ||||
| 
 | ||||
| static void test_expr_parse_modifier(void **arg) | ||||
| { | ||||
|     dice_expression_t e = NULL; | ||||
|     int error = 0, i = 0; | ||||
|     int64_t result = 0; | ||||
| 
 | ||||
|     e = dice_expression_parse("1d20+3+5", &error); | ||||
| 
 | ||||
|     assert_non_null(e); | ||||
|     assert_int_equal(error, 0); | ||||
| 
 | ||||
|     for (i = 0; i < 100000; i++) { | ||||
|         assert_true(dice_expression_evaluate(e, &result)); | ||||
|         assert_true(result >= 9 && result <= 28); | ||||
|     } | ||||
| 
 | ||||
|     dice_expression_free(e); | ||||
| } | ||||
| 
 | ||||
| static void test_expr_parse_complex(void **arg) | ||||
| { | ||||
|     dice_expression_t e = NULL; | ||||
|     int error = 0, i = 0; | ||||
|     int64_t result = 0; | ||||
| 
 | ||||
|     e = dice_expression_parse("1d8+(3+5)+1d6+5d4", &error); | ||||
| 
 | ||||
|     assert_non_null(e); | ||||
|     assert_int_equal(error, 0); | ||||
| 
 | ||||
|     for (i = 0; i < 100000; i++) { | ||||
|         assert_true(dice_expression_evaluate(e, &result)); | ||||
|         assert_true(result >= 15 && result <= 42); | ||||
|     } | ||||
| 
 | ||||
|     dice_expression_free(e); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| int main(int ac, char **av) | ||||
| { | ||||
|     const struct CMUnitTest tests[] = { | ||||
|         cmocka_unit_test(test_expr_parse_none), | ||||
|         cmocka_unit_test(test_expr_parse_simple), | ||||
|         cmocka_unit_test(test_expr_parse_modifier), | ||||
|         cmocka_unit_test(test_expr_parse_complex), | ||||
|     }; | ||||
| 
 | ||||
|     return cmocka_run_group_tests(tests, NULL, NULL); | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user