change folder, start work on new version

This commit is contained in:
Francesco Mecca 2024-09-16 18:05:24 +02:00
parent 7618e510af
commit f3eecaef78
15 changed files with 394 additions and 34 deletions

1
Pentole/LICENSE Symbolic link
View file

@ -0,0 +1 @@
../LICENSE

View file

@ -3,10 +3,14 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageId>Pentole</PackageId>
<Version>0.0.1</Version>
<Authors>Francesco Mecca</Authors>
<Company>Bugless24</Company>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="binaryprefix.fs" />
<Compile Include="pervasives.fs" /> <Compile Include="pervasives.fs" />
<Compile Include="string.fs" /> <Compile Include="string.fs" />
<Compile Include="option.fs" /> <Compile Include="option.fs" />

160
Pentole/binaryprefix.fs Normal file
View file

@ -0,0 +1,160 @@
module Pentole.BinaryPrefix
module Bits =
module IECScale =
type IECBit =
| B
| Kb
| Mb
| Gb
| Tb
| Pb
type Bit =
| Bit of double
| Kb of double
| Mb of double
| Gb of double
| Tb of double
| Pb of double
member this.bytes =
match this with
| Bit.Bit i -> i
| Bit.Kb i -> i * 1000.0 / 8.0
| Bit.Mb i -> i * 1000.0 * 1000.0 / 8.0
| Bit.Gb i -> i * 1000.0 * 1000.0 * 1000.0 / 8.0
| Bit.Tb i -> i * 1000.0 * 1000.0 * 1000.0 * 1000.0 / 8.0
| Bit.Pb i -> i * 1000.0 * 1000.0 * 1000.0 * 1000.0 * 1000.0 / 8.0
type System.Double with
member this.bit = Bit this
member this.Kb = Bit this
member this.Mb = Mb this
member this.Gb = Gb this
member this.Tb = Tb this
member this.Pb = Pb this
let private get_i_bit = function
| Kb i | Mb i | Gb i | Tb i | Pb i
| Bit.Bit i -> i
let change_scale (scale: IECScale.IECBit) (old_value: Bit) =
let x = get_i_bit old_value
let up, base_ =
match old_value with
| Bit _ -> 0.0, 1000.0
| Kb _ -> 1.0, 1000.0
| Mb _ -> 2.0, 1000.0
| Gb _ -> 3.0, 1000.0
| Tb _ -> 4.0, 1000.0
| Pb _ -> 5.0, 1000.0
let down, kst =
match scale with
| IECScale.IECBit.B -> 0.0, Bit
| IECScale.IECBit.Kb -> 1.0, Kb
| IECScale.IECBit.Mb -> 2.0, Mb
| IECScale.IECBit.Gb -> 3.0, Gb
| IECScale.IECBit.Tb -> 4.0, Tb
| IECScale.IECBit.Pb -> 5.0, Pb
x * (base_ ** (up - down)) |> kst
module Bytes =
type Byte =
| Byte of double
| KB of double
| MB of double
| GB of double
| TB of double
| PB of double
| KiB of double
| MiB of double
| GiB of double
| TiB of double
| PiB of double
member this.bytes =
match this with
| Byte.Byte i -> i
| Byte.KB i -> i * 1000.0
| Byte.MB i -> i * 1000.0 * 1000.0
| Byte.GB i -> i * 1000.0 * 1000.0 * 1000.0
| Byte.TB i -> i * 1000.0 * 1000.0 * 1000.0 * 1000.0
| Byte.PB i -> i * 1000.0 * 1000.0 * 1000.0 * 1000.0 * 1000.0
| Byte.KiB i -> i * 1024.0
| Byte.MiB i -> i * 1024.0 * 1024.0
| Byte.GiB i -> i * 1024.0 * 1024.0 * 1024.0
| Byte.TiB i -> i * 1024.0 * 1024.0 * 1024.0 * 1024.0
| Byte.PiB i -> i * 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0
type System.Double with
member this.byte = Byte.Byte this
member this.KB = KB this
member this.MB = MB this
member this.GB = GB this
member this.TB = TB this
member this.PB = PB this
member this.KiB = KiB this
member this.MiB = MiB this
member this.GiB = GiB this
member this.TiB = TiB this
member this.PiB = PiB this
let private get_i_byte = function
| KB i | MB i | GB i | TB i | PB i
| KiB i | MiB i | GiB i | TiB i | PiB i
| Byte.Byte i -> i
module IECScale =
type IECByte =
| B
| KB
| KiB
| MB
| MiB
| GB
| GiB
| TB
| TiB
| PB
| PiB
let change_scale (scale: IECScale.IECByte) (old_value: Byte) =
let x = get_i_byte old_value
let up, base_ =
match old_value with
| KB _ -> 1.0, 1000.0
| MB _ -> 2.0, 1000.0
| GB _ -> 3.0, 1000.0
| TB _ -> 4.0, 1000.0
| PB _ -> 5.0, 1000.0
| Byte.KiB _ -> 1.0, 1024.0
| Byte.MiB _ -> 2.0, 1024.0
| Byte.GiB _ -> 3.0, 1024.0
| Byte.TiB _ -> 4.0, 1024.0
| Byte.PiB _ -> 5.0, 1024.0
| Byte.Byte _ -> 0.0, 1000.0
let down, kst =
match scale with
| IECScale.IECByte.B -> 0.0, Byte
| IECScale.IECByte.KB -> 1.0, KB
| IECScale.IECByte.MB -> 2.0, MB
| IECScale.IECByte.GB -> 3.0, GB
| IECScale.IECByte.TB -> 4.0, TB
| IECScale.IECByte.PB -> 5.0, PB
| IECScale.IECByte.KiB -> 1.0, KiB
| IECScale.IECByte.MiB -> 2.0, MiB
| IECScale.IECByte.GiB -> 3.0, GiB
| IECScale.IECByte.TiB -> 4.0, TiB
| IECScale.IECByte.PiB -> 5.0, PiB
x * 8.0 * (base_ ** (up - down)) |> kst

182
Pentole/bytesize.fs Normal file
View file

@ -0,0 +1,182 @@
module Pentole.BinaryPrefix
type Bit =
| Bit of double
| Kb of double
| Mb of double
| Gb of double
| Tb of double
| Pb of double
member this.bytes =
match this with
| Bit.Bit i -> i
| Bit.Kb i -> i * 1000.0 / 8.0
| Bit.Mb i -> i * 1000.0 * 1000.0 / 8.0
| Bit.Gb i -> i * 1000.0 * 1000.0 * 1000.0 / 8.0
| Bit.Tb i -> i * 1000.0 * 1000.0 * 1000.0 * 1000.0 / 8.0
| Bit.Pb i -> i * 1000.0 * 1000.0 * 1000.0 * 1000.0 * 1000.0 / 8.0
type Byte =
| Byte of double
| KB of double
| MB of double
| GB of double
| TB of double
| PB of double
| KiB of double
| MiB of double
| GiB of double
| TiB of double
| PiB of double
member this.bytes =
match this with
| Byte.Byte i -> i
| Byte.KB i -> i * 1000.0
| Byte.MB i -> i * 1000.0 * 1000.0
| Byte.GB i -> i * 1000.0 * 1000.0 * 1000.0
| Byte.TB i -> i * 1000.0 * 1000.0 * 1000.0 * 1000.0
| Byte.PB i -> i * 1000.0 * 1000.0 * 1000.0 * 1000.0 * 1000.0
| Byte.KiB i -> i * 1024.0
| Byte.MiB i -> i * 1024.0 * 1024.0
| Byte.GiB i -> i * 1024.0 * 1024.0 * 1024.0
| Byte.TiB i -> i * 1024.0 * 1024.0 * 1024.0 * 1024.0
| Byte.PiB i -> i * 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0
type System.Double with
member this.bit = Bit this
member this.Kb = Bit this
member this.Mb = Mb this
member this.Gb = Gb this
member this.Tb = Tb this
member this.Pb = Pb this
member this.byte = Bit this
member this.KB = Bit this
member this.MB = Mb this
member this.GB = Gb this
member this.TB = Tb this
member this.PB = Pb this
member this.KiB = Bit this
member this.MiB = Mb this
member this.GiB = Gb this
member this.TiB = Tb this
member this.PiB = Pb this
module =
type IECBitUnit =
| Bit
| Kilobit
| Megabit
| Gigabit
| Terabit
| Petabit
type IECByteUnit =
| Byte
| Kilobyte
| Kibibyte
| Megabyte
| Mebibyte
| Gigabyte
| Gibibyte
| Terabyte
| Tebibyte
| Petabyte
| Pebibyte
let private get_i_byte = function
| KB i | MB i | GB i | TB i | PB i
| KiB i | MiB i | GiB i | TiB i | PiB i
| Byte.Byte i -> i
let convert_bytes (scale: IECBitUnit) (old_value: Byte) =
let x = get_i_byte old_value
let up, base_ =
match old_value with
| Byte.Byte _ -> 0.0, 1000.0
| KB _ -> 1.0, 1000.0
| MB _ -> 2.0, 1000.0
| GB _ -> 3.0, 1000.0
| TB _ -> 4.0, 1000.0
| PB _ -> 5.0, 1000.0
| KiB _ -> 1.0, 1024.0
| MiB _ -> 2.0, 1024.0
| GiB _ -> 3.0, 1024.0
| TiB _ -> 4.0, 1024.0
| PiB _ -> 5.0, 1024.0
let down =
match scale with
| Bit -> 0.0
| Kilobit -> 1.0
| Megabit -> 2.0
| Gigabit -> 3.0
| Terabit -> 4.0
| Petabit -> 5.0
let new_value = x * 8.0 * (base_ ** (up - down))
match scale with
| Bit -> Bit.Bit new_value
| Kilobit -> Bit.Kb new_value
| Megabit -> Bit.Mb new_value
| Gigabit -> Bit.Gb new_value
| Terabit -> Bit.Tb new_value
| Petabit -> Bit.Pb new_value
let inline convert_bytes (scale: IECByteUnit) (old_value: Byte) =
let x = get_i_byte old_value
let up, base_ =
match old_value with
| KB _ -> 1.0, 1000.0
| MB _ -> 2.0, 1000.0
| GB _ -> 3.0, 1000.0
| TB _ -> 4.0, 1000.0
| PB _ -> 5.0, 1000.0
| KiB _ -> 1.0, 1024.0
| MiB _ -> 2.0, 1024.0
| GiB _ -> 3.0, 1024.0
| TiB _ -> 4.0, 1024.0
| PiB _ -> 5.0, 1024.0
| Byte.Byte _ -> 0.0, 1000.0
let down =
match scale with
| Kilobyte -> 1.0
| Megabyte -> 2.0
| Gigabyte -> 3.0
| Terabyte -> 4.0
| Petabyte -> 5.0
| Kibibyte -> 1.0
| Mebibyte -> 2.0
| Gibibyte -> 3.0
| Tebibyte -> 4.0
| Pebibyte -> 5.0
| Byte -> 0.0
let new_value = x * 8.0 * (base_ ** (up - down))
match scale with
| Byte -> Byte.Byte new_value
| Kilobyte -> KB new_value
| Megabyte -> MB new_value
| Gigabyte -> GB new_value
| Terabyte -> TB new_value
| Petabyte -> PB new_value
| Kibibyte -> KiB new_value
| Mebibyte -> MiB new_value
| Gibibyte -> GiB new_value
| Tebibyte -> TiB new_value
| Pebibyte -> PiB new_value

View file

@ -29,12 +29,12 @@ let private string_apply fun_ = function
| Absolute p -> fun_ p |> Absolute | Absolute p -> fun_ p |> Absolute
| Relative p -> fun_ p |> Relative | Relative p -> fun_ p |> Relative
/// <summary> /// <summary>
/// Return the parent path /// Return the parent path
/// </summary> /// </summary>
/// <param name="path"></param> /// <param name="path"></param>
let parent (path: Path) = let parent (path: Path) =
failwith "t" failwith "TODO"
/// <summary> /// <summary>
/// Return the extension of the given path /// Return the extension of the given path
@ -49,8 +49,8 @@ let extension = function
/// </summary> /// </summary>
/// <param name="path"></param> /// <param name="path"></param>
let basename = function let basename = function
| Absolute p ->System.IO.Path.GetFileNameWithoutExtension p | Absolute p -> System.IO.Path.GetFileNameWithoutExtension p
| Relative p ->System.IO.Path.GetFileNameWithoutExtension p | Relative p -> System.IO.Path.GetFileNameWithoutExtension p
/// <summary> /// <summary>
/// Concatenates `path` and `other` and adds a directory separator character between any of the path components if one is not already present. /// Concatenates `path` and `other` and adds a directory separator character between any of the path components if one is not already present.

1
Pentole/readme.org Symbolic link
View file

@ -0,0 +1 @@
../readme.org

View file

@ -3,10 +3,10 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59 VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "src", "src\src.fsproj", "{B6807554-26A8-44C1-9B51-4F29F66E439D}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "tests", "tests\tests.fsproj", "{48FCE2C1-5013-4574-8006-C56FEECEDBB5}" Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "tests", "tests\tests.fsproj", "{48FCE2C1-5013-4574-8006-C56FEECEDBB5}"
EndProject EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Pentole", "Pentole\Pentole.fsproj", "{9B2AA44B-FAC3-4723-BF07-6767E766284A}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -16,13 +16,13 @@ Global
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B6807554-26A8-44C1-9B51-4F29F66E439D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6807554-26A8-44C1-9B51-4F29F66E439D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6807554-26A8-44C1-9B51-4F29F66E439D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6807554-26A8-44C1-9B51-4F29F66E439D}.Release|Any CPU.Build.0 = Release|Any CPU
{48FCE2C1-5013-4574-8006-C56FEECEDBB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {48FCE2C1-5013-4574-8006-C56FEECEDBB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48FCE2C1-5013-4574-8006-C56FEECEDBB5}.Debug|Any CPU.Build.0 = Debug|Any CPU {48FCE2C1-5013-4574-8006-C56FEECEDBB5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48FCE2C1-5013-4574-8006-C56FEECEDBB5}.Release|Any CPU.ActiveCfg = Release|Any CPU {48FCE2C1-5013-4574-8006-C56FEECEDBB5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48FCE2C1-5013-4574-8006-C56FEECEDBB5}.Release|Any CPU.Build.0 = Release|Any CPU {48FCE2C1-5013-4574-8006-C56FEECEDBB5}.Release|Any CPU.Build.0 = Release|Any CPU
{9B2AA44B-FAC3-4723-BF07-6767E766284A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B2AA44B-FAC3-4723-BF07-6767E766284A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B2AA44B-FAC3-4723-BF07-6767E766284A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B2AA44B-FAC3-4723-BF07-6767E766284A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

11
tests/bytes_tests.fs Normal file
View file

@ -0,0 +1,11 @@
module Tests.BinaryPrefix
open NUnit.Framework
open Pentole.TestsExtensions
open Pentole.BinaryPrefix
[<Test>]
let split_test () =
Assert.are_equal (Bytes.KB 1) (Bytes.Byte 1000)
Assert.are_equal (Bytes.KiB 1) (Bytes.Byte 1024)

View file

@ -9,6 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="bytes_tests.fs" />
<Compile Include="string_tests.fs" /> <Compile Include="string_tests.fs" />
<Compile Include="path_tests.fs" /> <Compile Include="path_tests.fs" />
<Compile Include="Program.fs" /> <Compile Include="Program.fs" />
@ -23,7 +24,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\src\src.fsproj" /> <ProjectReference Include="..\Pentole\Pentole.fsproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>