Skip to content

Commit

Permalink
Merge pull request #2 from gamousquesORT/codigoAgosto23
Browse files Browse the repository at this point in the history
Codigo agosto23
  • Loading branch information
gamousquesORT authored Oct 1, 2023
2 parents aac4418 + 086dfa4 commit 79b2a9b
Show file tree
Hide file tree
Showing 22 changed files with 530 additions and 12 deletions.
10 changes: 10 additions & 0 deletions CleanCode/Ejemplos/ConditionalTofunct/ConditionalTofunct.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
23 changes: 23 additions & 0 deletions CleanCode/Ejemplos/ConditionalTofunct/PlaceHolder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Security.Cryptography.X509Certificates;

namespace ConditionalTofunct;

public class PlaceHolder
{
public DateTime FechaExpiracion { get; set; }
public bool AprobadoParaConsumo { get; set; }
public int IdInspector { get; set; }

public bool IsComestible()
{
if (FechaExpiracion > DateTime.Now && AprobadoParaConsumo
&& AprobadoParaConsumo == true && IdInspector !=0)
{
return true;
}
else
{
return false;
}
}
}
3 changes: 3 additions & 0 deletions CleanCode/Ejemplos/ConditionalTofunct/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// See https://aka.ms/new-console-template for more information

Console.WriteLine("Hello, World!");
6 changes: 6 additions & 0 deletions CleanCode/Ejemplos/Ejemplos.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RefactorCleanCodeTests", "R
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RefactorCleanCodeSource", "RefactorCleanCodeSource\RefactorCleanCodeSource.csproj", "{F688DAE3-C6B5-456B-8540-62B970442062}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConditionalTofunct", "ConditionalTofunct\ConditionalTofunct.csproj", "{0927109E-E341-4171-9551-89900ABBBEB5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -42,5 +44,9 @@ Global
{F688DAE3-C6B5-456B-8540-62B970442062}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F688DAE3-C6B5-456B-8540-62B970442062}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F688DAE3-C6B5-456B-8540-62B970442062}.Release|Any CPU.Build.0 = Release|Any CPU
{0927109E-E341-4171-9551-89900ABBBEB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0927109E-E341-4171-9551-89900ABBBEB5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0927109E-E341-4171-9551-89900ABBBEB5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0927109E-E341-4171-9551-89900ABBBEB5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
4 changes: 2 additions & 2 deletions CleanCode/Ejemplos/WithoutDemeter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

using Ejemplos;

Commerce commerce = new Commerce();
Store store = new Store();
Customer customer = new Customer();
Wallet w = customer.Wallet;
w.Money = 100;
commerce.Checkout(customer, 110);
store.Checkout(customer, 110);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Ejemplos;

public class Commerce
public class Store
{
public void Checkout(Customer customer, decimal amount)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace OriginalCode;

public class operations_on_numbers
{
private int total;
private int contador;

public operations_on_numbers()
{
total = 0;
contador = 0;
}

public int magic_function(List<int> ns)
{
foreach (int n in ns)
{
if (n % 2 == 0)
{
total += n;
contador++;
}
}

if (contador == 0)
{
throw new Exception("La lista no contiene numeros pares ");
}
else
{
return total / contador;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToRefactorExamples", "ToRefactorExamples\ToRefactorExamples.csproj", "{FE7BCF27-1F9C-4A46-AF71-944539A34BF1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RefactoringExamplesTests", "RefactoringExamplesTests\RefactoringExamplesTests.csproj", "{4A1F1396-469A-44CF-A84F-5AF1164ABAF9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OriginalCode", "OriginalCode\OriginalCode.csproj", "{C214ABEA-E7C3-435D-A89D-1C74A1D34029}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FE7BCF27-1F9C-4A46-AF71-944539A34BF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FE7BCF27-1F9C-4A46-AF71-944539A34BF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE7BCF27-1F9C-4A46-AF71-944539A34BF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE7BCF27-1F9C-4A46-AF71-944539A34BF1}.Release|Any CPU.Build.0 = Release|Any CPU
{4A1F1396-469A-44CF-A84F-5AF1164ABAF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A1F1396-469A-44CF-A84F-5AF1164ABAF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A1F1396-469A-44CF-A84F-5AF1164ABAF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A1F1396-469A-44CF-A84F-5AF1164ABAF9}.Release|Any CPU.Build.0 = Release|Any CPU
{C214ABEA-E7C3-435D-A89D-1C74A1D34029}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C214ABEA-E7C3-435D-A89D-1C74A1D34029}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C214ABEA-E7C3-435D-A89D-1C74A1D34029}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C214ABEA-E7C3-435D-A89D-1C74A1D34029}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\ToRefactorExamples\ToRefactorExamples.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using ToRefactorExamples;

namespace RefactoringExamplesTests;

public class RefactoringTests
{
[Fact]
public void Should_Return_the_Average_Given_a_Set_Of_One_Even_Number()
{
List<int> numbers = new() {8};
operations_on_numbers rf = new operations_on_numbers();
int want = 8;
int got = rf.magic_function(numbers);
Assert.Equal(want, got);
}

[Fact]
public void Should_Return_The_Average_Given_a_Set_Of_Two_Even_Numbers()
{
List<int> numbers = new() { 2, 6 };
operations_on_numbers rf = new operations_on_numbers();
int want = 4;
int got = rf.magic_function(numbers);
Assert.Equal(want, got);
}

[Fact]
public void Should_Return_The_Even_Number_Given_A_SetWith_One_Even_And_One_Odd_Number()
{
List<int> numbers = new() { 2, 7 };
operations_on_numbers rf = new operations_on_numbers();
int want = 2;
int got = rf.magic_function(numbers);
Assert.Equal(want, got);
}

[Fact]
public void Should_Return_The_Even_Number_Given_A_SetWith_More_Than_One_Even_And_One_Odd_Number()
{
List<int> numbers = new() {0, 2, 7 };
operations_on_numbers rf = new operations_on_numbers();
int want = 1;
int got = rf.magic_function(numbers);
Assert.Equal(want, got);
}

[Fact]
public void Should_Return_TheAverage_Given_An_Odd_SetOf_Even_Numbers_Including_Zero()
{
List<int> numbers = new() {0, 2, 6, 8, 12, 24, 28 };
operations_on_numbers rf = new operations_on_numbers();
int want = Convert.ToInt32(numbers.Average());
int got = rf.magic_function(numbers);
Assert.Equal(want, got);
}

[Fact]
public void Should_Return_TheAverage_Given_ASetOf_Even_Numbers_Containing_a_Cero()
{
List<int> numbers = new() {0, 6, 8, 12, 24, 28 };
operations_on_numbers rf = new operations_on_numbers();
int want = Convert.ToInt32(numbers.Average());
int got = rf.magic_function(numbers);
Assert.Equal(want, got);
}

[Fact]
public void Should_Throw_ArgumentExcep_Given_An_Empty_Set()
{
List<int> numbers = new();
operations_on_numbers rf = new operations_on_numbers();

// Renombre para usar la ArgumentException
Assert.Throws<Exception>(() => rf.magic_function(numbers));
}

[Fact]
public void Should_Return_Message_Given_ASet_of_Odd_Numbers()
{
List<int> numbers = new() { 1, 5, 7,35 };
operations_on_numbers rf = new operations_on_numbers();
string want = "La lista no contiene numeros pares";
var got = Assert.Throws<Exception>(() => rf.magic_function(numbers));
Assert.Contains(want, got.Message);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace ToRefactorExamples;

/* - Cambiar todos los Nombres no significativos a significativos.
* - Utilizar la convención de C# de programación y en Ingles
* - Refactoree y aplique Clean Code en todo el código
* ->reemplazar números magicos
* ->reemplazar comentarios por nombres significativos
* -> extraer métodos
*
*/
public class operations_on_numbers
{
private int total;
private int contador;

public operations_on_numbers()
{
total = 0;
contador = 0;
}

public int magic_function(List<int> ns)
{
foreach (int n in ns)
{
if (n % 2 == 0)
{
total += n;
contador++;
}
}

if (contador == 0)
{
throw new Exception("La lista no contiene numeros pares ");
}
else
{
return total / contador;
}
}
}


19 changes: 10 additions & 9 deletions TDD/practica2023_1/docs/FizBuzz.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
* Crear una clase que tenga un método que dado un número retorne:
Fizz si el número es divisible por 3
Buzz si el número es divisible por 5
FizzBuzzLogic si el número es divisible por 3 y 5
Si el número no es divisible por 3 ni 5 retorna el número
FizzBuzz si el número es divisible por 3 y 5
Si el número no es divisible por 3 ni 5 retorna el número
Si el número es negativo o > 100 retorna un error
*
* DEfinir tests
* 1. Se llama a la funcion para ver que no exista la clase y todo funciona
* Definir tests
* 1. Se llama a la funcion para ver que no exista la clase
* 2. Se pasa un número divisible por 3 y retorna Fizz
* 3. Se pasa un número divisible por 5 y retorna Buzz
* 4. se pasa un numero divisble por 2 y 5 y retorna FizzBuzzLogic
* 4. se pasa un numero divisble por 3 y 5 y retorna FizzBuzz
* 4. Se pasa un número no divisble por 3 y retorna el numero como string
* 5. se pasa nulo y retorna excepción
* 6. se pasa un número negativo y retorna excepción
*
*/
* 5. se pasa un número negativo y retorna excepción
* 6. se pasa un número mayor que 100 retorna una excepción
*
*/
22 changes: 22 additions & 0 deletions TDD/practica2023_2/FizzBuzz/FizzBuzz.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FizzBuzzProdCode", "FizzBuzzProdCode\FizzBuzzProdCode.csproj", "{429E1E85-D105-4130-A929-8CFE50A1323C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FizzBuzzTest", "FizzBuzzTest\FizzBuzzTest.csproj", "{1FAFDCE2-618A-4038-93DA-22C6C81764F9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{429E1E85-D105-4130-A929-8CFE50A1323C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{429E1E85-D105-4130-A929-8CFE50A1323C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{429E1E85-D105-4130-A929-8CFE50A1323C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{429E1E85-D105-4130-A929-8CFE50A1323C}.Release|Any CPU.Build.0 = Release|Any CPU
{1FAFDCE2-618A-4038-93DA-22C6C81764F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1FAFDCE2-618A-4038-93DA-22C6C81764F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FAFDCE2-618A-4038-93DA-22C6C81764F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FAFDCE2-618A-4038-93DA-22C6C81764F9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Loading

0 comments on commit 79b2a9b

Please sign in to comment.