mirror of
https://git.tonybark.com/tonytins/swiftlyfox.git
synced 2026-05-12 06:53:32 -04:00
Added Square and Equilateral Triangle classes
This commit is contained in:
parent
1c40a688e4
commit
53ba21d774
9 changed files with 154 additions and 45 deletions
1
.swift-version
Normal file
1
.swift-version
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
6.3.1
|
||||||
44
.vscode/launch.json
vendored
Normal file
44
.vscode/launch.json
vendored
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "swift",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder:swiftlyfox}",
|
||||||
|
"name": "Debug swiftyfox",
|
||||||
|
"target": "swiftyfox",
|
||||||
|
"configuration": "debug",
|
||||||
|
"preLaunchTask": "swift: Build Debug swiftyfox"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "swift",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder:swiftlyfox}",
|
||||||
|
"name": "Release swiftyfox",
|
||||||
|
"target": "swiftyfox",
|
||||||
|
"configuration": "release",
|
||||||
|
"preLaunchTask": "swift: Build Release swiftyfox"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "swift",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder:swiftlyfox}",
|
||||||
|
"name": "Debug swiftlyfox",
|
||||||
|
"target": "swiftlyfox",
|
||||||
|
"configuration": "debug",
|
||||||
|
"preLaunchTask": "swift: Build Debug swiftlyfox"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "swift",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder:swiftlyfox}",
|
||||||
|
"name": "Release swiftlyfox",
|
||||||
|
"target": "swiftlyfox",
|
||||||
|
"configuration": "release",
|
||||||
|
"preLaunchTask": "swift: Build Release swiftlyfox"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
20
.vscode/tasks.json
vendored
Normal file
20
.vscode/tasks.json
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "swift: Build swiftlyfox",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "swift",
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"--swift-sdk",
|
||||||
|
"swift-6.3.1-RELEASE_wasm",
|
||||||
|
"--product",
|
||||||
|
"swiftlyfox"
|
||||||
|
],
|
||||||
|
"group": "build",
|
||||||
|
"problemMatcher": [],
|
||||||
|
"detail": "Custom build for WASM target"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
{
|
|
||||||
"originHash" : "f3097f72511ac559eeb33298fe5d1aac2e73e26e2133181df5c213b8394d0ab0",
|
|
||||||
"pins" : [
|
|
||||||
{
|
|
||||||
"identity" : "swift-argument-parser",
|
|
||||||
"kind" : "remoteSourceControl",
|
|
||||||
"location" : "https://github.com/apple/swift-argument-parser",
|
|
||||||
"state" : {
|
|
||||||
"revision" : "cdd0ef3755280949551dc26dee5de9ddeda89f54",
|
|
||||||
"version" : "1.6.2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version" : 3
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +1,23 @@
|
||||||
// swift-tools-version: 6.2
|
// swift-tools-version: 6.3
|
||||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||||
|
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
name: "swiftyfox",
|
name: "swiftlyfox",
|
||||||
dependencies: [
|
dependencies: [
|
||||||
// other dependencies
|
// other dependencies
|
||||||
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"),
|
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
// Targets are the basic building blocks of a package, defining a module or a test suite.
|
// Targets are the basic building blocks of a package, defining a module or a test suite.
|
||||||
// Targets can depend on other targets in this package and products from dependencies.
|
// Targets can depend on other targets in this package and products from dependencies.
|
||||||
.executableTarget(
|
.executableTarget(
|
||||||
name: "swiftyfox",
|
name: "swiftlyfox",
|
||||||
dependencies: [
|
),
|
||||||
// other dependencies
|
.testTarget(
|
||||||
.product(name: "ArgumentParser", package: "swift-argument-parser"),
|
name: "swiftlyfoxTests",
|
||||||
]),
|
dependencies: ["swiftlyfox"]
|
||||||
|
),
|
||||||
]
|
],
|
||||||
|
swiftLanguageModes: [.v6]
|
||||||
)
|
)
|
||||||
|
|
|
||||||
6
Sources/swiftlyfox/swiftlyfox.swift
Normal file
6
Sources/swiftlyfox/swiftlyfox.swift
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
@main
|
||||||
|
struct swiftlyfox {
|
||||||
|
static func main() {
|
||||||
|
print("Hello, world!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
import ArgumentParser
|
|
||||||
|
|
||||||
@main
|
|
||||||
struct swiftyfox: ParsableCommand {
|
|
||||||
@Flag var verbose = false
|
|
||||||
|
|
||||||
static func main() {
|
|
||||||
print("Hello, world!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -27,13 +27,68 @@ func calcStats(scores: [Int]) -> (min: Int, max: Int, sum: Int) {
|
||||||
let stats = calcStats(scores: [5, 3, 100, 3, 9])
|
let stats = calcStats(scores: [5, 3, 100, 3, 9])
|
||||||
let sum = stats.sum // 120
|
let sum = stats.sum // 120
|
||||||
|
|
||||||
class Shape {
|
class NamedShape {
|
||||||
var numberOfSides = 0
|
var numberOfSides = 0
|
||||||
|
var name: String
|
||||||
|
|
||||||
|
init(name: String = "Heptagon") {
|
||||||
|
self.name = name
|
||||||
|
}
|
||||||
|
|
||||||
func simpleDescription() -> String {
|
func simpleDescription() -> String {
|
||||||
return "A shape with \(numberOfSides) sides."
|
return "A shape with \(numberOfSides) sides."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var shape = Shape()
|
class Square: NamedShape {
|
||||||
|
var sideLength: Double
|
||||||
|
|
||||||
|
init(sideLength: Double, name: String = "Square") {
|
||||||
|
self.sideLength = sideLength
|
||||||
|
super.init(name: name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func area() -> Double {
|
||||||
|
return sideLength * sideLength
|
||||||
|
}
|
||||||
|
|
||||||
|
override func simpleDescription() -> String {
|
||||||
|
return "A Square with \(numberOfSides) sides."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class EquilateralTriangle: NamedShape {
|
||||||
|
var sideLength: Double
|
||||||
|
|
||||||
|
var perimeter: Double {
|
||||||
|
get {
|
||||||
|
return 3.0 * sideLength
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
sideLength = newValue / 3.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init(sideLength: Double, name: String = "Square") {
|
||||||
|
self.sideLength = sideLength
|
||||||
|
super.init(name: name)
|
||||||
|
numberOfSides = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
func area() -> Double {
|
||||||
|
return sideLength * sideLength
|
||||||
|
}
|
||||||
|
|
||||||
|
override func simpleDescription() -> String {
|
||||||
|
return "A Equilateral Triangle with \(numberOfSides) sides."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var shape = NamedShape()
|
||||||
shape.numberOfSides = 7
|
shape.numberOfSides = 7
|
||||||
var shapeDesc = shape.simpleDescription()
|
shape.simpleDescription()
|
||||||
|
|
||||||
|
var square = Square(sideLength: 5.2)
|
||||||
|
square.area()
|
||||||
|
square.simpleDescription()
|
||||||
|
|
|
||||||
8
Tests/swiftlyfoxTests/swiftlyfoxTests.swift
Normal file
8
Tests/swiftlyfoxTests/swiftlyfoxTests.swift
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
import Testing
|
||||||
|
@testable import swiftlyfox
|
||||||
|
|
||||||
|
@Test func example() async throws {
|
||||||
|
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
|
||||||
|
// Swift Testing Documentation
|
||||||
|
// https://developer.apple.com/documentation/testing
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue