/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to tests/dynamic_array.c

  • Committer: Gustav Hartvigsson
  • Date: 2015-04-28 12:25:20 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20150428122520-n90grm1k1l318ooa
* Finnished SLinkedList.
  * Still needs to be tested.
* Made s_object_initialize take the name of the class
* made s_object_free free the name
* fixed s_dynamic_array_free. It now takes a sboolean to tell it
  to free the data in the array or not.
* fixed a typo in defs.h
* fixed the the test of the dynamic array.
* switched (SObject *) to S_OBJECT () for casting in SError.
* changed hash_t to size_t.
* general code cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "SimpleTypeSystem.h"
2
2
#include "test_macros.h"
3
3
#include <stdlib.h>
 
4
#include <stdint.h>
4
5
#include <time.h>
5
6
 
6
7
int test_dynamic_array (void) {
21
22
  int r_n = rand ();
22
23
  int r_p = rand () % 20;
23
24
  
24
 
  s_dynamic_array_set (array, r_p, (spointer) r_n);
 
25
  s_dynamic_array_set (array, r_p, (spointer)(intptr_t) r_n);
25
26
  
26
 
  test_case ((int) s_dynamic_array_get (array, r_p) == r_n,
 
27
  test_case ((intptr_t) s_dynamic_array_get (array, r_p) == r_n,
27
28
             "The the inserted random number matches the generated number.");
28
29
  
29
30
  s_print ("Adding a number (12345) to index 21\n");
30
31
  
31
 
  s_dynamic_array_set (array, 21, (spointer) 12345);
 
32
  s_dynamic_array_set (array, 21, (spointer)(intptr_t) 12345);
32
33
  
33
34
  test_case (s_dynamic_array_size (array) > 20, "The new size is larger then the old size.");
34
35
  
35
36
  s_print ("Filling array with numbers: 0-32\n");
36
37
  
37
38
  for (int i = 0; i < s_dynamic_array_size (array); i++) {
38
 
    s_dynamic_array_set (array, i, (spointer) i);
 
39
    s_dynamic_array_set (array, i, (spointer)(intptr_t) i);
39
40
  }
40
41
  for (int i = 0; i < s_dynamic_array_size (array); i++) {
41
 
    int got_val = s_dynamic_array_get(array, i);
42
 
    test_case (got_val == i, "The stored value (%d) matches the expected value (%d).", i, got_val);
 
42
    int got_val = (intptr_t) s_dynamic_array_get(array, i);
 
43
    test_case (got_val == i, "The stored value (%d) matches the expected value (%d).", (int) i, got_val);
43
44
  }
44
45
  
 
46
  s_dynamic_array_free (array, FALSE);
 
47
  
45
48
  end_unit ();
46
49
}