File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed
algorithm_exercises_csharp_test/hackerrank/interview_preparation_kit/miscellaneous
algorithm_exercises_csharp/hackerrank/interview_preparation_kit/miscellaneous Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change
1
+ // @link Problem definition [[docs/hackerrank/interview_preparation_kit/miscellaneous/flipping-bits.md]]
2
+
3
+ namespace algorithm_exercises_csharp . hackerrank . interview_preparation_kit . miscellaneous ;
4
+
5
+ using System . Diagnostics . CodeAnalysis ;
6
+ using System . Text ;
7
+
8
+ public static class FlippingBitsAlternative
9
+ {
10
+ public static long flippingBits ( long n )
11
+ {
12
+ return ~ n & 0xFFFFFFFF ; // Use bitwise NOT and mask to ensure 32 bits
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ namespace algorithm_exercises_csharp_test . hackerrank . interview_preparation_kit . miscellaneous ;
2
+
3
+ using algorithm_exercises_csharp_test . common ;
4
+ using algorithm_exercises_csharp . hackerrank . interview_preparation_kit . miscellaneous ;
5
+
6
+ [ TestClass ]
7
+ public class FlippingBitsAlternativeTest
8
+ {
9
+ public class FlippingBitsAlternativeTestCaseTest ( long input , long answer )
10
+ {
11
+ public long Input { get ; } = input ;
12
+ public long Answer { get ; } = answer ;
13
+ }
14
+
15
+ public class FlippingBitsAlternativeTestCase ( string title , List < FlippingBitsAlternativeTestCaseTest > tests )
16
+ {
17
+ public string Title { get ; } = title ;
18
+ public List < FlippingBitsAlternativeTestCaseTest > Tests { get ; } = tests ;
19
+ }
20
+
21
+ private List < FlippingBitsAlternativeTestCase > testCases { get ; set ; } = default ! ;
22
+
23
+ [ TestInitialize ]
24
+ public void testInitialize ( )
25
+ {
26
+ testCases = JsonLoader . resourceLoad < List < FlippingBitsAlternativeTestCase > > (
27
+ "hackerrank/interview_preparation_kit/miscellaneous/flipping_bits.testcases.json"
28
+ ) ?? [ ] ;
29
+ }
30
+
31
+ [ TestMethod ]
32
+ public void testFlippingBitsAlternative ( )
33
+ {
34
+ long result ;
35
+
36
+ foreach ( FlippingBitsAlternativeTestCase tests in testCases )
37
+ {
38
+ foreach ( FlippingBitsAlternativeTestCaseTest test in tests . Tests )
39
+ {
40
+ result = FlippingBitsAlternative . flippingBits ( test . Input ) ;
41
+ Assert . AreEqual (
42
+ test . Answer ,
43
+ result ,
44
+ string . Format (
45
+ System . Globalization . CultureInfo . InvariantCulture ,
46
+ "FlippingBitsAlternative.flippingBits({0}) => must be: {1}" ,
47
+ test . Input ,
48
+ test . Answer
49
+ )
50
+ ) ;
51
+ }
52
+ }
53
+ }
54
+ }
You can’t perform that action at this time.
0 commit comments