File tree Expand file tree Collapse file tree 5 files changed +26
-3
lines changed Expand file tree Collapse file tree 5 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -50,8 +50,9 @@ $ coverage report -m
50
50
Different algorithmic programs. Grouped by general topic.
51
51
52
52
#### Bitwise Algorithms
53
- * [ Hamming Distance] ( algorithms/bitwise/operations.py )
54
- * [ Hamming Weight] ( algorithms/bitwise/operations.py )
53
+ * [ Hamming Distance] ( algorithms/bitwise/hamming_ops.py )
54
+ * [ Hamming Weight] ( algorithms/bitwise/hamming_ops.py )
55
+ * [ Binary Complement] ( algorithms/bitwise/complement.py )
55
56
56
57
#### Mathematical Algorithms
57
58
* [ Fibonacci] ( algorithms/math/fibonacci.py )
Original file line number Diff line number Diff line change
1
+ def complement (num ):
2
+ """
3
+ Find the non-zero padded binary compelement.
4
+
5
+ """
6
+ if not num :
7
+ return 1
8
+ i = 1
9
+ while i <= num :
10
+ num ^= i
11
+ i = i << 1
12
+ return num
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ import unittest
2
+ from algorithms .bitwise .complement import complement
3
+
4
+ class TestComplement (unittest .TestCase ):
5
+
6
+ def test_complement (self ):
7
+ self .assertEqual (0b010 , complement (0b101 ))
8
+ self .assertEqual (0b01 , complement (0b10 ))
9
+ self .assertEqual (0b0011000101000001111 , complement (0b1100111010111110000 ))
10
+ self .assertEqual (0b1 , complement (0b0 ))
Original file line number Diff line number Diff line change 1
1
import unittest
2
- from algorithms .bitwise .operations import hamming_distance , hamming_weight
2
+ from algorithms .bitwise .hamming_ops import hamming_distance , hamming_weight
3
3
4
4
class test_bitwise (unittest .TestCase ):
5
5
You can’t perform that action at this time.
0 commit comments