Fundamentals
Strings
Data Types
package kata import "fmt" // MinsToHours converts Minutes to Hours and Minutes func MinsToHours(mins int) string { return fmt.Sprintf("%d:%.2d", mins / 60, mins % 60) }
fn minutes(mins: u32) -> String {format!("{}:{:02}", mins / 60, mins % 60)- package kata
- import "fmt"
- // MinsToHours converts Minutes to Hours and Minutes
- func MinsToHours(mins int) string {
- return fmt.Sprintf("%d:%.2d", mins / 60, mins % 60)
- }
package kata_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "codewarrior/kata" ) var _ = Describe("When converting Minutes to Hours and Minutes", func() { It("should return the correct Hours and Minutes representation", func() { Expect(MinsToHours(0)).To(Equal("0:00")) Expect(MinsToHours(1)).To(Equal("0:01")) Expect(MinsToHours(18)).To(Equal("0:18")) Expect(MinsToHours(13267)).To(Equal("221:07")) Expect(MinsToHours(985)).To(Equal("16:25")) Expect(MinsToHours(351)).To(Equal("5:51")) Expect(MinsToHours(156113)).To(Equal("2601:53")) }) })
#[test]fn test_minutes() {assert_eq!(minutes(0), "0:00");assert_eq!(minutes(1), "0:01");assert_eq!(minutes(18), "0:18");assert_eq!(minutes(13267), "221:07");assert_eq!(minutes(985), "16:25");assert_eq!(minutes(351), "5:51");assert_eq!(minutes(156113), "2601:53");}- package kata_test
- import (
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
- . "codewarrior/kata"
- )
- var _ = Describe("When converting Minutes to Hours and Minutes", func() {
- It("should return the correct Hours and Minutes representation", func() {
- Expect(MinsToHours(0)).To(Equal("0:00"))
- Expect(MinsToHours(1)).To(Equal("0:01"))
- Expect(MinsToHours(18)).To(Equal("0:18"))
- Expect(MinsToHours(13267)).To(Equal("221:07"))
- Expect(MinsToHours(985)).To(Equal("16:25"))
- Expect(MinsToHours(351)).To(Equal("5:51"))
- Expect(MinsToHours(156113)).To(Equal("2601:53"))
- })
- })
package kata // CalcAgeOnMars calculates the age on Mars from on a age on Earth func CalcAgeOnMars(age int) int { return age * 365 / 687 }
package main- package kata
import "fmt"func main() {var age intfmt.Printf("Enter your age on Earth: ")_, err := fmt.Scanf("%d", &age)if (err != nil) {fmt.Println(err)}age = age * 365 / 687fmt.Printf("Your age on the surface of Mars is %d years old.\n", age)}- // CalcAgeOnMars calculates the age on Mars from on a age on Earth
- func CalcAgeOnMars(age int) int {
- return age * 365 / 687
- }
package kata_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "codewarrior/kata" ) var _ = Describe("When calculating the age in mars", func() { It("should result 3 martian years for 7 earth years", func() { Expect(CalcAgeOnMars(7)).To(Equal(3)) }) It("should result 10 martian years for 20 earth years", func() { Expect(CalcAgeOnMars(20)).To(Equal(10)) }) It("should result 22 martian years for 42 earth years", func() { Expect(CalcAgeOnMars(42)).To(Equal(22)) }) })
- package kata_test
- import (
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
- . "codewarrior/kata"
- )
- var _ = Describe("When calculating the age in mars", func() {
- It("should result 3 martian years for 7 earth years", func() {
- Expect(CalcAgeOnMars(7)).To(Equal(3))
- })
- It("should result 10 martian years for 20 earth years", func() {
- Expect(CalcAgeOnMars(20)).To(Equal(10))
- })
- It("should result 22 martian years for 42 earth years", func() {
- Expect(CalcAgeOnMars(42)).To(Equal(22))
- })
- })