From 068afd62766764e7b86a01883ac6a4f4ade1aee8 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 9 Sep 2015 09:00:17 -0400 Subject: [PATCH] core/random: Convert to C And convert the unit test while we're at it. Signed-off-by: Anna Schumaker --- core/queue.cpp | 2 ++ core/{random.cpp => random.c} | 2 +- include/core/random.h | 18 ++++-------------- tests/core/Sconscript | 2 +- tests/core/queue.cpp | 2 ++ tests/core/{random.cpp => random.c} | 2 +- 6 files changed, 11 insertions(+), 17 deletions(-) rename core/{random.cpp => random.c} (98%) rename tests/core/{random.cpp => random.c} (98%) diff --git a/core/queue.cpp b/core/queue.cpp index 7dcc7566..d030c1e8 100644 --- a/core/queue.cpp +++ b/core/queue.cpp @@ -2,7 +2,9 @@ * Copyright 2013 (c) Anna Schumaker. */ #include +extern "C" { #include +} #include #include diff --git a/core/random.cpp b/core/random.c similarity index 98% rename from core/random.cpp rename to core/random.c index 5736f220..b6db9056 100644 --- a/core/random.cpp +++ b/core/random.c @@ -1,4 +1,4 @@ -/** +/* * Copyright 2014 (c) Anna Schumaker */ #ifdef CONFIG_TESTING diff --git a/include/core/random.h b/include/core/random.h index 6f37f194..c64eda74 100644 --- a/include/core/random.h +++ b/include/core/random.h @@ -1,4 +1,4 @@ -/** +/* * Copyright 2014 (c) Anna Schumaker */ #ifndef OCARINA_CORE_RANDOM_H @@ -18,23 +18,14 @@ static inline unsigned int _pick_random() { return rand(); } #endif /* CONFIG_TESTING */ -/** - * Seed the random number generator. - * - * @param n Value used to initialize the RNG - */ + +/* Seed the random number generator. */ static inline void random_seed(unsigned int n) { _seed_random(n); } -/** - * Get a random number in the specified range. - * - * @param min Minimum value that will be returned. - * @param max Maximum value that will be returned. - * @return A random value where min <= value <= max. - */ +/* Returns a random number X, where min <= value <= max. */ static inline unsigned int random_range(unsigned int min, unsigned int max) { if (min >= max) @@ -42,5 +33,4 @@ static inline unsigned int random_range(unsigned int min, unsigned int max) return min + (_pick_random() % (max - min)); } - #endif /* OCARINA_CORE_RANDOM_H */ diff --git a/tests/core/Sconscript b/tests/core/Sconscript index 97c84c53..966c2cbe 100644 --- a/tests/core/Sconscript +++ b/tests/core/Sconscript @@ -15,7 +15,7 @@ Export("core_objs") res = [ CoreTest("version", "version.c") ] res += [ CoreTest("string", "string.c") ] -res += [ CoreTest("random", "random.cpp") ] +res += [ CoreTest("random", "random.c") ] res += [ CoreTest("file", "file.cpp") ] res += [ CoreTest("database", "database.cpp") ] res += [ CoreTest("index", "index.cpp") ] diff --git a/tests/core/queue.cpp b/tests/core/queue.cpp index a6ee7380..107cd915 100644 --- a/tests/core/queue.cpp +++ b/tests/core/queue.cpp @@ -2,7 +2,9 @@ * Copyright 2014 (c) Anna Schumaker. */ #include +extern "C" { #include +} #include #include "test.h" diff --git a/tests/core/random.cpp b/tests/core/random.c similarity index 98% rename from tests/core/random.cpp rename to tests/core/random.c index 61dd36a9..fae7d0b4 100644 --- a/tests/core/random.cpp +++ b/tests/core/random.c @@ -3,7 +3,7 @@ */ #include #include -#include "test.h" +#include static void test_rng(unsigned int seed)