Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- devel

env:
BUILD_TYPE: Release
BUILD_TYPE: Debug

jobs:
build:
Expand All @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v3

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -S . -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install
run: cmake -B ${{github.workspace}}/build -S . -L -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install

- name: Build
run: cmake --build ${{github.workspace}}/build --target install --config ${{env.BUILD_TYPE}}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
All changes to the repository will be reported here

## [0.2.2]
### Fixed
- Number of nodes allocated in create_graph

## [0.2.1]
### Updated
- cmake exports
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Author Marco M. Mosca, email: marcomichele.mosca@gmail.com
]]

cmake_minimum_required(VERSION 3.5.0)
project(graphoc VERSION 0.2.1 LANGUAGES C)
project(graphoc VERSION 0.2.2 LANGUAGES C)

include(CTest)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ int main(int argc, char* argv[]) {
## Tests (only on static build)
```
cmake -B build -S . -L -DCMAKE_INSTALL_PREFIX=<install_folder>
cmake --build .\build --target install --config Release
cmake --build .\build --target install --config Debug
cd build
ctest --build-config Release --build-target install
ctest --build-config Debug --build-target install
```
4 changes: 2 additions & 2 deletions graphoc/include/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ int save_graph (FILE * nodefile, FILE * edgefile, graph_t* g);

/** Create a graph
\param n Number of Nodes
\param labels Pointer to array of labels:
\param labels Pointer to array of labels with NULL terminator:
static const char* labels[] = {
"CAMBRIDGE",
"LONDON",
"MACHESTER",
"MANCHESTER",
"LIVERPOOL",
NULL,
};
Expand Down
20 changes: 6 additions & 14 deletions graphoc/src/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,21 @@ graph_t * create_graph (unsigned int n, char **labels)
errno = EINVAL;
if ((labels == NULL) || (n==0)) {return NULL;};
errno = ENOMEM;
if ((k=malloc(sizeof(graph_t))) == NULL) {return NULL;};
nodo=malloc(n * sizeof(node_t));
if (nodo == NULL) {free(k);return NULL;};
if ((k=(graph_t*)malloc(sizeof(graph_t))) == NULL) {return NULL;};
if ((nodo=(node_t*)malloc((n+1) * sizeof(node_t))) == NULL) {free(k);return NULL;};
k->size = n;

while (i<n && labels[i] != NULL)
{
len = strlen((const char*) labels[i]);
s=malloc((len) * sizeof(char)+1);
if (s== NULL) {return NULL;};
if((s=(char*)malloc(len * sizeof(char) + 1)) == NULL) {return NULL;};
strcpy(s,(const char*) labels[i]);
(nodo+i)->label = s;

(nodo+i)->label = s;
(nodo+i)->adj = NULL;
i++;
}
(nodo+i)->label=NULL;
(nodo+i)->adj = NULL;
k->node = nodo;
return k;
}
Expand Down Expand Up @@ -462,16 +460,13 @@ graph_t* load_graph (FILE * nodefile, FILE * edgefile)

int save_graph (FILE * nodefile, FILE * edgefile, graph_t* g)
{
int i=0, len;
int i=0;
node_t* node;
edge_t* ag;
double d;
unsigned int j;
char* s;

if((nodefile==NULL) || (edgefile==NULL) || g==NULL) {errno=EINTR;return -1;};

s=malloc(3 * sizeof(char));
errno=EIO;
node = g->node;
while((node+i)->label != NULL)
Expand All @@ -481,14 +476,11 @@ int save_graph (FILE * nodefile, FILE * edgefile, graph_t* g)
while(ag != NULL)
{
d=ag->weight;
sprintf(s,"%f",d);
j=ag->label;
len = strlen((node+i)->label)+strlen((node+j)->label)+strlen(s);
if((fprintf(edgefile, "%s:%s:%.1f\n", (node+i)->label,(node+j)->label,d))<0) {return -1;};
ag=ag->next;
}
i++;
}
free(s);
return 0;
}
6 changes: 3 additions & 3 deletions tests/test_get_degree.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void test_get_degree()
{
graph_t* graph;
if ( ( graph = create_graph(5, labels) ) == NULL ) {
exit(EXIT_FAILURE);
exit(EXIT_FAILURE);
}
for(char** p=edges; *p!=NULL; p++){
if ( add_edge(graph,*p) == -1 ) {
Expand All @@ -40,6 +40,6 @@ void test_get_degree()

int main()
{
test_get_degree();
return 0;
test_get_degree();
return 0;
}
16 changes: 8 additions & 8 deletions tests/test_get_edge_count.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ Author Marco M. Mosca, email: marcomichele.mosca@gmail.com

void test_get_edge_count()
{
graph_t* graph;
if ( ( graph = create_graph(5, labels) ) == NULL ) {
graph_t* graph;
if ( ( graph = create_graph(5, labels) ) == NULL ) {
exit(EXIT_FAILURE);
}
for(char** e=edges; *e!=NULL; e++){
}
for(char** e=edges; *e!=NULL; e++){
if ( add_edge(graph,*e) == -1 ) {
fprintf(stderr, "Adding edge failed: %s", *e);
perror("");
exit(EXIT_FAILURE);
}
}
}
assert(get_edge_count(graph) == 6);
free_graph(&graph);
free_graph(&graph);
}

int main()
{
test_get_edge_count();
return 0;
test_get_edge_count();
return 0;
}