Skip to content
Snippets Groups Projects
Commit 74f40c10 authored by Mamadu-lamarana Bah's avatar Mamadu-lamarana Bah :speech_balloon:
Browse files

fin de séance

parents 5f2362ae 7788dae5
Branches
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ Loïc Scoth ...@@ -8,6 +8,7 @@ Loïc Scoth
## TODO ## TODO
ajout commande execution/tests ajout commande execution/tests
Ce qui ne vas pas
## Description du projet ## Description du projet
......
graph {
"[5, 25]"
}
src/ArbreB/Graph.gv.jpg

2.7 KiB

#import Node as Bnode #import Node as Bnode
from Node import * from Node import Node
from Visualization import * #from Visualization import Visualization
class Btree() : class Btree() :
...@@ -23,24 +23,28 @@ class Btree() : ...@@ -23,24 +23,28 @@ class Btree() :
def insertion(self, value): def insertion(self, value):
""" """
Exemple(s): Exemple(s):
>>> a =Btree(2, Node([12, 42], [Node([2, 3]), Node([25]), Node([50])])) # >>> a =Btree(2, Node([12, 42], [Node([2, 3]), Node([25]), Node([50])]))
>>> a.insertion(1) # >>> a.insertion(1)
True # True
>>> a.search(1) # >>> a.search(1)
(Node([1]), 0) # (Node([1]), 0)
>>> b= Btree(3, Node([12,25,50], [Node([1,11]), Node([20]), Node([100])])) # >>> b= Btree(3, Node([12,25,50], [Node([1,11]), Node([20]), Node([100])]))
>>> b.insertion(10) # >>> b.insertion(10)
True # True
>>> b.search(10) # >>> b.search(10)
(Node([1, 10, 11]), 1) # (Node([1, 10, 11]), 1)
>>> Btree(2, Node([4, 10], [Node([1, 3]), Node([25]), Node([50])])).insertion(4) # >>> Btree(2, Node([4, 10], [Node([1, 3]), Node([25]), Node([50])])).insertion(4)
True # True
>>> c = Btree(2,Node([1, 10]))
>>> print(c.insertion(15))
""" """
print(self.root)
fini, milieu, g, d = self.root.insert(value, self.k) fini, milieu, g, d = self.root.insert(value, self.k)
if (not fini): if (not fini):
new_root = Node([milieu], [g, d]) new_root = Node([milieu], [g, d])
self.root = new_root self.root = new_root
print(self.root)
return True return True
...@@ -62,6 +66,11 @@ class Btree() : ...@@ -62,6 +66,11 @@ class Btree() :
""" """
(ok, _, _, _) = self.root.is_ArbreB(self.k, True) (ok, _, _, _) = self.root.is_ArbreB(self.k, True)
return ok return ok
def equals(self, otherObject):
if not isinstance(otherObject, Btree):
return False
return (self.root.keys == otherObject.root.keys and self.k == otherObject.k)
def __repr__(self) : def __repr__(self) :
return f"Btree({self.root})" return f"Btree({self.root})"
......
from util import recherche_dichotomique from util import recherche_dichotomique
from Visualization import * #from Visualization import *
from BTree import * #from BTree import *
class Node() : class Node() :
...@@ -80,7 +80,10 @@ class Node() : ...@@ -80,7 +80,10 @@ class Node() :
""" """
Return : (node, index) or Nothing Return : (node, index) or Nothing
Exemple(s): Exemple(s):
>>> node = Node([5])
>>> node = Node([])
>>> node.insert(5,1)
(True, None, None, None)
>>> node.insert(20, 2) >>> node.insert(20, 2)
(True, None, None, None) (True, None, None, None)
>>> node.search(20) >>> node.search(20)
...@@ -107,6 +110,7 @@ class Node() : ...@@ -107,6 +110,7 @@ class Node() :
>>> node.insert(1, 3) >>> node.insert(1, 3)
(True, None, None, None) (True, None, None, None)
""" """
(found, index) = recherche_dichotomique(value, self.keys) (found, index) = recherche_dichotomique(value, self.keys)
if (not found) : if (not found) :
......
import graphviz import graphviz
from Node import * from Node import Node
from BTree import * from BTree import Btree
class Visualization() : class Visualization() :
...@@ -11,6 +11,8 @@ class Visualization() : ...@@ -11,6 +11,8 @@ class Visualization() :
self.add_node_to_graph(self.btree.root) self.add_node_to_graph(self.btree.root)
def add_node_to_graph(self, node): def add_node_to_graph(self, node):
# nodeKeys = repr(node.keys)
print(repr(node.keys))
nodeKeys = repr(node.keys) nodeKeys = repr(node.keys)
self.g.node(nodeKeys) self.g.node(nodeKeys)
for child in node.childs: for child in node.childs:
......
import unittest #import unittest
from Node import * from Node import Node
from util import *
from Visualization import Visualization
from BTree import Btree
class experimentation: class experimentation:
def setUp(self): def __init__(self):
self.node = Node([12, 42], ) self.btree = Btree(2, Node([]))
self.experimentationInsert1()
def experimentationInsert1(self):
#self.btree.insertion(2)
#self.isCorrect(Btree(2,Node([2])))
#self.btree.insertion(4)
#self.isCorrect(Btree(2,Node([2,4])))
for n in [2, 4, 5] + list(range(6, 37, 2)) + [7, 9, 11, 13]:
self.btree.insertion(n)
# TODO Visualization(self.btree).render()
print(self.btree)
def isCorrect(self, BTreeTest):
if (self.btree.equals(BTreeTest)):
print("Correct")
else:
print("error")
...@@ -16,14 +48,19 @@ class experimentation: ...@@ -16,14 +48,19 @@ class experimentation:
if __name__ == "__main__":
experiment = experimentation()
if __name__ == "__main__":
import sys
sys.path.insert(1, './src')
sys.path.insert(2, '../src')
from Node import *
unittest.main() # if __name__ == "__main__":
\ No newline at end of file # import sys
# sys.path.insert(1, './src')
# sys.path.insert(2, '../src')
# from Node import *
#
# unittest.main()
# import doctest
# doctest.testmod(verbose=False)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment