parent
793c12c9b9
commit
cc7b810fd0
@ -0,0 +1,88 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define TABLE_SIZE 100
|
||||
|
||||
typedef struct Node {
|
||||
int key;
|
||||
char value[256];
|
||||
struct Node* next;
|
||||
} Node;
|
||||
|
||||
typedef struct Edge {
|
||||
Node* from;
|
||||
Node* to;
|
||||
double cost;
|
||||
struct Edge* next;
|
||||
} Edge;
|
||||
|
||||
typedef struct Graph {
|
||||
Node* nodes[TABLE_SIZE];
|
||||
Edge* edges[TABLE_SIZE];
|
||||
} Graph;
|
||||
|
||||
unsigned int hash(int key) {
|
||||
return key % TABLE_SIZE;
|
||||
}
|
||||
|
||||
void insertNode(Graph* g, int key, const char* value) {
|
||||
unsigned int index = hash(key);
|
||||
Node* new_node = (Node*) malloc(sizeof(Node));
|
||||
if (new_node) {
|
||||
new_node->key = key;
|
||||
strcpy(new_node->value, value);
|
||||
new_node->next = g->nodes[index];
|
||||
g->nodes[index] = new_node;
|
||||
}
|
||||
}
|
||||
|
||||
Node* findNode(Graph* g, int key) {
|
||||
unsigned int index = hash(key);
|
||||
Node* node = g->nodes[index];
|
||||
while (node) {
|
||||
if (node->key == key)
|
||||
return node;
|
||||
node = node->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void insertEdge(Graph* g, int fromKey, int toKey, double cost) {
|
||||
Node* fromNode = findNode(g, fromKey);
|
||||
Node* toNode = findNode(g, toKey);
|
||||
if (fromNode && toNode) {
|
||||
unsigned int index = hash(fromKey);
|
||||
Edge* new_edge = (Edge*) malloc(sizeof(Edge));
|
||||
if (new_edge) {
|
||||
new_edge->from = fromNode;
|
||||
new_edge->to = toNode;
|
||||
new_edge->cost = cost;
|
||||
new_edge->next = g->edges[index];
|
||||
g->edges[index] = new_edge;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void initGraph(Graph* g) {
|
||||
for (int i = 0; i < TABLE_SIZE; i++) {
|
||||
g->nodes[i] = NULL;
|
||||
g->edges[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
Graph g;
|
||||
initGraph(&g);
|
||||
|
||||
insertNode(&g, 1, "Node 1");
|
||||
insertNode(&g, 2, "Node 2");
|
||||
insertEdge(&g, 1, 2, 0.5);
|
||||
|
||||
Node* n = findNode(&g, 1);
|
||||
if (n) {
|
||||
printf("Found node: %s\n", n->value);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
import unittest,importlib,BeautifulReport,cffi
|
||||
|
||||
def load():
|
||||
src = open("add.c").read()
|
||||
inc = open("add.h").read()
|
||||
|
||||
builder = cffi.FFI()
|
||||
|
||||
builder.cdef(inc)
|
||||
builder.set_source("addLib",src)
|
||||
builder.compile()
|
||||
|
||||
md = importlib.import_module("addLib")
|
||||
|
||||
return md.lib
|
||||
|
||||
md = load()
|
||||
|
||||
class AddTestCase(unittest.TestCase):
|
||||
|
||||
def test_case1(self):
|
||||
'''
|
||||
第1个case
|
||||
:return:
|
||||
'''
|
||||
self.assertEqual(md.addition(1,2),1+2)
|
||||
print('md.addition(1,2),1+2')
|
||||
|
||||
def test_case2(self):
|
||||
'''
|
||||
第2个case
|
||||
:return:
|
||||
'''
|
||||
self.assertEqual(md.addition(1,5),1+2)
|
||||
|
||||
print('md.addition(1,5),1+2')
|
||||
|
||||
sut = unittest.TestSuite()
|
||||
sut.addTest(unittest(AddTestCase))
|
||||
run = BeautifulReport.BeautifulReport(sut)
|
||||
|
||||
run.report(filename="test.html",description="add单元测试")
|
||||
|
@ -0,0 +1,45 @@
|
||||
{
|
||||
"active": true,
|
||||
"name": "resize1",
|
||||
"path": "resize_wasm.so",
|
||||
"port": 10000,
|
||||
"relative-deadline-us": 78574,
|
||||
"argsize": 1,
|
||||
"http-req-headers": [],
|
||||
"http-req-content-type": "image/jpeg",
|
||||
"http-req-size": 1024000,
|
||||
"http-resp-headers": [],
|
||||
"http-resp-size": 1024000,
|
||||
"http-resp-content-type": "image/png"
|
||||
},
|
||||
|
||||
{
|
||||
"active": true,
|
||||
"name": "png2bmp1",
|
||||
"path": "C-Image-Manip_wasm.so",
|
||||
"port": 10001,
|
||||
"relative-deadline-us": 78574,
|
||||
"argsize": 1,
|
||||
"http-req-headers": [],
|
||||
"http-req-content-type": "image/png",
|
||||
"http-req-size": 4096000,
|
||||
"http-resp-headers": [],
|
||||
"http-resp-size": 4096000,
|
||||
"http-resp-content-type": "image/bmp"
|
||||
},
|
||||
|
||||
{
|
||||
"active": true,
|
||||
"name": "cifar10_1",
|
||||
"path": "cifar10_wasm.so",
|
||||
"port": 10002,
|
||||
"relative-deadline-us": 78574,
|
||||
"argsize": 1,
|
||||
"http-req-headers": [],
|
||||
"http-req-content-type": "image/bmp",
|
||||
"http-req-size": 4096000,
|
||||
"http-resp-headers": [],
|
||||
"http-resp-size": 1024,
|
||||
"http-resp-content-type": "text/plain",
|
||||
"tail-module": true
|
||||
}
|
Loading…
Reference in new issue