fn odd_count(n: u64) -> u64 { n / 2 }
#import <Foundation/Foundation.h>@interface SampleClass:NSObject/* method declaration */- (int)odd_count:(int)n;@end@implementation SampleClass- (int) odd_count:(int) n{//your code hereint odd_counter = 0;for (int i = 1; i < n; i=i+2) {// Numbers that are divisible by 2if (i % 2 != 0)odd_counter++;}return odd_counter;}@end- fn odd_count(n: u64) -> u64 {
- n / 2
- }
#[test] fn test_odd_count() { assert_eq!(odd_count(0), 0); assert_eq!(odd_count(1), 0); assert_eq!(odd_count(2), 1); assert_eq!(odd_count(3), 1); assert_eq!(odd_count(4), 2); assert_eq!(odd_count(5), 2); assert_eq!(odd_count(6), 3); assert_eq!(odd_count(20), 10); assert_eq!(odd_count(35), 17); }
// TODO: replace with your own tests, these are just how-to examples.// Codewars uses UnitKit unit testing framework.// See https://github.com/codewars/codewars.com/wiki/UnitKit@implementation TestSuite- (void)testCanBeSolvedWithBasicComputations{int ret;SampleClass *sampleClass = [[SampleClass alloc]init];ret = [sampleClass odd_count:5];UKIntsEqual(2, ret);ret = [sampleClass odd_count:15023];UKIntsEqual(7511, ret);}@end- #[test]
- fn test_odd_count() {
- assert_eq!(odd_count(0), 0);
- assert_eq!(odd_count(1), 0);
- assert_eq!(odd_count(2), 1);
- assert_eq!(odd_count(3), 1);
- assert_eq!(odd_count(4), 2);
- assert_eq!(odd_count(5), 2);
- assert_eq!(odd_count(6), 3);
- assert_eq!(odd_count(20), 10);
- assert_eq!(odd_count(35), 17);
- }