import khoury.CapturedResult import khoury.EnabledTest import khoury.captureResults import khoury.input import khoury.runEnabledTests import khoury.testSame // TODO: Design the function getFullName that uses the input // function to get a first and last name from the // keyboard, print the full name to the screen, and // then return the new FullName they create. // // represents the parts of a person's name, first and last data class FullName(val firstName: String, val lastName: String) val fullNameHP = FullName("Harry", "Potter") val fullNameHG = FullName("Hermione", "Granger") // converts a full name value to the corresponding // string with first and last name fun fNToString(fullName: FullName): String { return "${ fullName.firstName } ${ fullName.lastName }" } @EnabledTest fun testFNToString() { testSame( fNToString(fullNameHP), "Harry Potter", "harry", ) testSame( fNToString(fullNameHG), "Hermione Granger", "hermione", ) } val promptFirstName = "Please enter a first name" val promptLastName = "Please enter a last name" // will get a first name and last name from the keyboard, // and then print the full name to the screen and return // the resulting combined full name fun getFullName(): FullName { println(promptFirstName) val firstName = input() println(promptLastName) val lastName = input() val resultFullName = FullName(firstName, lastName) println(fNToString(resultFullName)) return resultFullName } @EnabledTest fun testGetFullName() { testSame( captureResults( ::getFullName, "alice", "apple", ), CapturedResult( FullName("alice", "apple"), promptFirstName, promptLastName, "alice apple", ), "alice", ) testSame( captureResults( ::getFullName, "bob", "banana", ), CapturedResult( FullName("bob", "banana"), promptFirstName, promptLastName, "bob banana", ), "bob", ) } fun main() { } runEnabledTests(this) main()